- GUI
- Windows API tutorial
- Introduction to Windows API
- Windows API main functions
- System functions in Windows API
- Strings in Windows API
- Date & time in Windows API
- A window in Windows API
- First steps in UI
- Windows API menus
- Windows API dialogs
- Windows API controls I
- Windows API controls II
- Windows API controls III
- Advanced controls in Windows API
- Custom controls in Windows API
- The GDI in Windows API
- PyQt4 tutorial
- PyQt5 tutorial
- Qt4 tutorial
- Introduction to Qt4 toolkit
- Qt4 utility classes
- Strings in Qt4
- Date and time in Qt4
- Working with files and directories in Qt4
- First programs in Qt4
- Menus and toolbars in Qt4
- Layout management in Qt4
- Events and signals in Qt4
- Qt4 Widgets
- Qt4 Widgets II
- Painting in Qt4
- Custom widget in Qt4
- The Breakout game in Qt4
- Qt5 tutorial
- Introduction to Qt5 toolkit
- Strings in Qt5
- Date and time in Qt5
- Containers in Qt5
- Working with files and directories in Qt5
- First programs in Qt5
- Menus and toolbars in Qt5
- Layout management in Qt5
- Events and signals in Qt5
- Qt5 Widgets
- Qt5 Widgets II
- Painting in Qt5
- Custom widget in Qt5
- Snake in Qt5
- The Breakout game in Qt5
- PySide tutorial
- Tkinter tutorial
- Tcl/Tk tutorial
- Qt Quick tutorial
- Java Swing tutorial
- JavaFX tutorial
- Java SWT tutorial
- wxWidgets tutorial
- Introduction to wxWidgets
- wxWidgets helper classes
- First programs in wxWidgets
- Menus and toolbars in wxWidgets
- Layout management in wxWidgets
- Events in wxWidgets
- Dialogs in wxWidgets
- wxWidgets widgets
- wxWidgets widgets II
- Drag and Drop in wxWidgets
- Device Contexts in wxWidgets
- Custom widgets in wxWidgets
- The Tetris game in wxWidgets
- wxPython tutorial
- Introduction to wxPython
- First Steps
- Menus and toolbars
- Layout management in wxPython
- Events in wxPython
- wxPython dialogs
- Widgets
- Advanced widgets in wxPython
- Drag and drop in wxPython
- Internationalisation
- Application skeletons in wxPython
- The GDI
- Mapping modes
- Creating custom widgets
- Tips and Tricks
- wxPython Gripts
- The Tetris game in wxPython
- C# Winforms Mono tutorial
- Java Gnome tutorial
- Introduction to Java Gnome
- First steps in Java Gnome
- Layout management in Java Gnome
- Layout management II in Java Gnome
- Menus in Java Gnome
- Toolbars in Java Gnome
- Events in Java Gnome
- Widgets in Java Gnome
- Widgets II in Java Gnome
- Advanced widgets in Java Gnome
- Dialogs in Java Gnome
- Pango in Java Gnome
- Drawing with Cairo in Java Gnome
- Drawing with Cairo II
- Nibbles in Java Gnome
- QtJambi tutorial
- GTK+ tutorial
- Ruby GTK tutorial
- GTK# tutorial
- Visual Basic GTK# tutorial
- PyGTK tutorial
- Introduction to PyGTK
- First steps in PyGTK
- Layout management in PyGTK
- Menus in PyGTK
- Toolbars in PyGTK
- Signals & events in PyGTK
- Widgets in PyGTK
- Widgets II in PyGTK
- Advanced widgets in PyGTK
- Dialogs in PyGTK
- Pango
- Pango II
- Drawing with Cairo in PyGTK
- Drawing with Cairo II
- Snake game in PyGTK
- Custom widget in PyGTK
- PHP GTK tutorial
- C# Qyoto tutorial
- Ruby Qt tutorial
- Visual Basic Qyoto tutorial
- Mono IronPython Winforms tutorial
- Introduction
- First steps in IronPython Mono Winforms
- Layout management
- Menus and toolbars
- Basic Controls in Mono Winforms
- Basic Controls II in Mono Winforms
- Advanced Controls in Mono Winforms
- Dialogs
- Drag & drop in Mono Winforms
- Painting
- Painting II in IronPython Mono Winforms
- Snake in IronPython Mono Winforms
- The Tetris game in IronPython Mono Winforms
- FreeBASIC GTK tutorial
- Jython Swing tutorial
- JRuby Swing tutorial
- Visual Basic Winforms tutorial
- JavaScript GTK tutorial
- Ruby HTTPClient tutorial
- Ruby Faraday tutorial
- Ruby Net::HTTP tutorial
- Java 2D games tutorial
- Java 2D tutorial
- Cairo graphics tutorial
- PyCairo tutorial
- HTML5 canvas tutorial
- Python tutorial
- Python language
- Interactive Python
- Python lexical structure
- Python data types
- Strings in Python
- Python lists
- Python dictionaries
- Python operators
- Keywords in Python
- Functions in Python
- Files in Python
- Object-oriented programming in Python
- Modules
- Packages in Python
- Exceptions in Python
- Iterators and Generators
- Introspection in Python
- Ruby tutorial
- PHP tutorial
- Visual Basic tutorial
- Visual Basic
- Visual Basic lexical structure
- Basics
- Visual Basic data types
- Strings in Visual Basic
- Operators
- Flow control
- Visual Basic arrays
- Procedures & functions in Visual Basic
- Organizing code in Visual Basic
- Object-oriented programming
- Object-oriented programming II in Visual Basic
- Collections in Visual Basic
- Input & output
- Tcl tutorial
- C# tutorial
- Java tutorial
- AWK tutorial
- Jetty tutorial
- Tomcat Derby tutorial
- Jtwig tutorial
- Android tutorial
- Introduction to Android development
- First Android application
- Android Button widgets
- Android Intents
- Layout management in Android
- Android Spinner widget
- SeekBar widget
- Android ProgressBar widget
- Android ListView widget
- Android Pickers
- Android menus
- Dialogs
- Drawing in Android
- Java EE 5 tutorials
- Introduction
- Installing Java
- Installing NetBeans 6
- Java Application Servers
- Resin CGIServlet
- JavaServer Pages, (JSPs)
- Implicit objects in JSPs
- Shopping cart
- JSP & MySQL Database
- Java Servlets
- Sending email in a Servlet
- Creating a captcha in a Servlet
- DataSource & DriverManager
- Java Beans
- Custom JSP tags
- Object relational mapping with iBATIS
- Jsoup tutorial
- MySQL tutorial
- MySQL quick tutorial
- MySQL storage engines
- MySQL data types
- Creating, altering and dropping tables in MySQL
- MySQL expressions
- Inserting, updating, and deleting data in MySQL
- The SELECT statement in MySQL
- MySQL subqueries
- MySQL constraints
- Exporting and importing data in MySQL
- Joining tables in MySQL
- MySQL functions
- Views in MySQL
- Transactions in MySQL
- MySQL stored routines
- MySQL Python tutorial
- MySQL Perl tutorial
- MySQL C API programming tutorial
- MySQL Visual Basic tutorial
- MySQL PHP tutorial
- MySQL Java tutorial
- MySQL Ruby tutorial
- MySQL C# tutorial
- SQLite tutorial
- SQLite C tutorial
- SQLite PHP tutorial
- SQLite Python tutorial
- SQLite Perl tutorial
- SQLite Ruby tutorial
- SQLite C# tutorial
- SQLite Visual Basic tutorial
- PostgreSQL C tutorial
- PostgreSQL Python tutorial
- PostgreSQL Ruby tutorial
- PostgreSQL PHP tutorial
- PostgreSQL Java tutorial
- Apache Derby tutorial
- SQLAlchemy tutorial
- MongoDB PHP tutorial
- MongoDB Java tutorial
- MongoDB JavaScript tutorial
- MongoDB Ruby tutorial
- Spring JdbcTemplate tutorial
- JDBI tutorial
Dialogs in Tcl/Tk
In this part of the Tcl/Tk tutorial, we will work with dialogs.
Dialog windows or dialogs are an indispensable part of most modern GUI applications. A dialog is defined as a conversation between two or more persons. In a computer application a dialog is a window which is used to "talk" to the application. A dialog is used to input data, modify data, change the application settings etc. Dialogs are important means of communication between a user and a computer program.
Message boxes
Message boxes are convenient dialogs that provide messages to the user of the application. The message consists of text and image data. Message boxes in Tk are created with the tk_messageBox
command.
#!/usr/bin/wish # ZetCode Tcl/Tk tutorial # # In this program, we show various # message boxes. # # author: Jan Bodnar # last modified: March 2011 # website: www.zetcode.com frame .fr pack .fr ttk::button .fr.erButton -text Error -command onError grid .fr.erButton ttk::button .fr.wButton -text Warning -command onWarn grid .fr.wButton -row 1 -column 0 ttk::button .fr.queButton -text Question -command onQuest grid .fr.queButton -row 0 -column 1 -sticky we -columnspan 6 ttk::button .fr.infButton -text Information -command onInfo grid .fr.infButton -row 1 -column 1 proc onError {} { tk_messageBox -type ok -icon error -title Error \ -message "Could not open file" } proc onWarn {} { tk_messageBox -type ok -icon warning -title Warning \ -message "Deprecated function call" } proc onQuest {} { tk_messageBox -type ok -icon question -title Question \ -message "Are you sure to quit?" } proc onInfo {} { tk_messageBox -type ok -icon info -title Information \ -message "Download completed" } wm title . "message boxes" wm geometry . 300x150+300+300
We use the grid manager to set up a grid of four buttons. Each of the buttons shows a different message box.
ttk::button .fr.erButton -text Error -command onError grid .fr.erButton
We create an error button, which calls the onError procedure. Inside the method, we show the error message dialog. The button is placed into the first cell of the grid. Widgets inside the ttk
namespace are themed. The button
and ttk::button
are the same buttons in terms of functionality. The difference is that we can apply themes on the latter.
proc onError {} { tk_messageBox -type ok -icon error -title Error \ -message "Could not open file" }
In case we pressed the error button, we show the error dialog. We use the tk_messageBox
command to create the message box. The -type
option specifies which buttons are shown in the dialog. In our case it is a single OK button. The -icon
specifies the type of the icon to be shown. The -title
provides the title of the dialog and the -message
its message.

Color chooser
The color chooser is a dialog for selecting a colour. We use the tk_chooseColor
command to display the dialog.
#!/usr/bin/wish # ZetCode Tcl/Tk tutorial # # In this script, we use tk_chooseColor # dialog to change the colour of the text. # # author: Jan Bodnar # last modified: March 2011 # website: www.zetcode.com label .l -text ZetCode place .l -x 20 -y 90 button .b -text "Choose a color..." \ -command "onSelect .l" place .b -x 20 -y 30 wm title . "color dialog" wm geometry . 350x200+300+300 proc onSelect {widget} { set col \ [tk_chooseColor -title "Choose a color" -parent .] $widget configure -foreground $col }
We have a button and a label. Clicking on the button we show a color chooser dialog. We will change the colour of the label text by selecting a colour from the dialog.
label .l -text ZetCode place .l -x 20 -y 90
We create a label
widget and place it on the window.
button .b -text "Choose a color..." \ -command "onSelect .l" place .b -x 20 -y 30
We create a button
widget and place it on the window. We pass the widget path of the label to the onSelect
procedure, which shows the dialog and changes the colour of the label.
proc onSelect {widget} { set col \ [tk_chooseColor -title "Choose a color" -parent .] $widget configure -foreground $col }
Inside the onSelect
procedure, we show the dialog and change the label colour. First we display the dialog and store the chosen colour value in the col
variable. Later we use the configure
command to change the foreground of the label. The command is executed on the widget's path name. The label's path name was passed to the procedure.

File dialog
tk_getOpenFile
dialog allows a user to select a file from the filesystem.
#!/usr/bin/wish # ZetCode Tcl/Tk tutorial # # In this program, we use the # tk_getOpenFile dialog to select a file from # a filesystem. # # author: Jan Bodnar # last modified: March 2011 # website: www.zetcode.com set types { {"All Source Files" {.tcl .tk } } {"Image Files" {.gif .png .jpg} } {"All files" *} } proc onSelect { label } { global types set file [tk_getOpenFile -filetypes $types -parent .] $label configure -text $file } label .l -text "..." place .l -x 20 -y 90 button .b -text "Select a file" \ -command "onSelect .l" place .b -x 20 -y 30 wm title . "openfile" wm geometry . 350x200+300+300
In our code example, we use the tk_getOpenFile
dialog to select a file and display its name in a label
widget.
set types { {"All Source Files" {.tcl .tk } } {"Image Files" {.gif .png .jpg} } {"All files" *} }
These are file filters. These filters can be used to show only specific files in the dialog.
proc onSelect { label } { global types set file [tk_getOpenFile -filetypes $types -parent .] $label configure -text $file }
We show the dialog with the tk_getOpenFile
command. We apply the file filters using the -filetypes
option. The selected file name is stored in the file variable. The configure
command is used to change the text of the label.

In this part of the Tcl/Tk tutorial, we worked with dialog windows.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论