Python Desktop Apps with Tkinter. Example Tkinter module. This example opens a blank desktop window. The tkinter module is part of the standard library. To use tkinter, import the tkinter module. 1: from tkinter import. This is tkinter with underscore t, it has been renamed in Python 3. 2.5 Tkinter widget appearance 17 3 Building an application 18 3.1 Calculator example: key features 21 3.2 Calculator example: source code 21 3.3 Examining the application structure 27 3.4 Extending the application 28 Part 2 Displays 29 4 Tkinter widgets 31 4.1 Tkinter widget tour 31 Toplevel 32, Frame 33, Label 35, Button 36, Entry 37.
Posted by2 years ago
Archived
Hi everyone.
I've read a LOT of programming books, so I decided it was time to give one back to the community. Since I love working with the Tkinter library to create GUIs, I decided to write a book which will hopefully help teach newbies how to get started with writing their own GUI applications.
I've finally finished and released Learn Tkinter By Example. It's free, released under Creative Commons with the Python source code released with the MIT licence. The Latex source code is also available alongside the PDF book, should anybody want that for any reason.
The book is available from my Github here, along with more details:
All feedback is welcome (preferably constructive rather than just insults!) As the book states towards the end, I am completely open to working on developing it further if need be. Source code comments, questions, and changes can be sent to me through Github, and anything book-related can be messaged to me directly here or through twitter (@Dvlv292).
I hope this book will be of use to some of you.
69 comments
Tkinter in Python comes with a lot of good widgets. Widgets are standard graphical user interface (GUI) elements, like different kinds of buttons and menus. Most of the Tkinter widgets are given here.
Label Widget
A Label widget shows text to the user. You can update the widget programmatically to, for example, provide a readout or status bar.
Button Widget
A Button can be on and off. When a user clicks it, the button emits an event. Images can be displayed on buttons.
Entry Widget
An Entry widget gets text input from the user.
Radiobutton Widget
A Radiobutton lets you put buttons together, so that only one of them can be clicked. If one button is on and the user clicks another, the first is set to off. Use Tkinter variables (mainly Tkinter.IntVar and Tkinter.StringVar) to access its state.
Radiobutton Widget (Alternate)
You can display a Radiobutton without the dot indicator. In that case it displays its state by being sunken or raised.
Checkbutton Widget
A Checkbutton records on/off or true/false status. Like a Radiobutton, a Checkbutton widget can be displayed without its check mark, and you need to use a Tkinter variable to access its state.
Scale Widget: Horizontal
Use a Scale widget when you want a slider that goes from one value to another. You can set the start and end values, as well as the step. For example, you can have a slider that has only the even values between 2 and 100. Access its current value by its get method; set its current value by its set method.
Scale Widget: Vertical
A Scale widget can be vertical (up and down).
Text Widget
Use a Text widget to show large areas of text. The Text widget lets the user edit and search.
LabelFrame Widget
The LabelFrame acts as a parent widget for other widgets, displaying them with a title and an outline. LabelFrame has to have a child widget before you can see it.
Canvas Widget
You use a Canvas widget to draw on. It supports different drawing methods.
Listbox Widget
Listbox lets the user choose from one set of options or displays a list of items.
Menu Widget
The Menu widget can create a menu bar. Creating menus can be hard, especially if you want drop-down menus. To do that, you use a separate Menu widget for each drop-down menu you’re creating.
OptionMenu Widget
The OptionMenu widget lets the user choose from a list of options. To use the OptionMenu the right way, you’ll probably need to bind it to a separate callback that updates other information based on the user’s selection. Get the currently selected value with its get method.