The aim of this video is to add a label widget to your GUI.
- [Instructor] In the previous video we created a simple GUI form, In this video, we're going to add a label widget to our form. We're extending the first video. We will leave the GUI resizable, so don't use the code from the second file, notresizable.py. In order to add a label widget to our GUI we're importing the Ttk module from tkinter.
Please note, the two import statements. We'll also a code just above win.mainloop. Let's see what that is. Here, we're importing a separate module from tkinter. The Ttk module has some advanced widgets that make our GUI look great.
In a sense, Ttk is an extension within tkinter. We still need to import tkinter itself, but we have to specify that we now want to also use Ttk from tkinter. This line adds the label to the GUI just before we call mainloop. We're passing our window instance into the Ttk label constructor and setting the text property. This becomes the text our label will display. We're also making use of the grid layout manager which we'll explore in much more depth in section two.
Okay, let me save it as AddingALabel.py. Let's run this now. We could see that this file adds a label to our GUI. Note how our GUI suddenly got much smaller than in previous videos. The reason why it became so small is that we added a widget to our form. Without a widget, tkinter uses a default size. Adding a widget causes optimization which generally means using as little space as necessary to display the widgets.
If we make the text to the label longer, the GUI will expand automatically. We will cover this automatic form size adjustment in a later video, in section two. There's a task for you. Try resizing and maximizing this GUI without a label and watch what happens. Awesome. In this video we have successfully added a label. In the next video, we'll make more features to it, like buttons and text box widgets.
Note: This course was created by Packt Publishing. We are pleased to host this training in our library.
- Creating buttons and widgets
- Adding labels and features
- Expanding a GUI dynamically
- Aligning frames and embedding frames
- Creating menu bars, message boxes, and tooltips
- Using module-level global variables
- Coding in classes
- Using Matplotlib to create charts
- Working with multiple threads, queues, and TCP/IP
- Using URLOpen to read data from websites
- Localizing a GUI and preparing for internationalization
- Testing a GUI using unit tests and Eclipse PyDev IDE
- Using the wxPython library
- Using Tkinter, PyOpenGL, and Pyglet
Skill Level Intermediate
1. Creating the GUI Form and Adding Widgets
2. Layout Management
3. Look and Feel Customization
4. Data and Classes
Using the StringVar() type8m 14s
5. Matplotlib Charts
6. Threads and Networking
7. Storing Data in Our MySQL Database via Our GUI
8. Internationalization and Testing
9. Extending Our GUI with the wxPython Library
10. Creating Amazing 3D GUIs with PyOpenGL and Pyglet
11. Best Practices
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.