Python Tkinter Label Introduction
As I said in the earlier article Python Tkinter Tutorials Introduction, we have many widgets are available in the Tkinter module and among that Label is the most functional,helpful and key widget.Simply a label is the widget class of Tkinter.
How To Write A String Using Tkinter Labels
Let me write a simple text using Tk labels in python programming and then I will explain you.
If you run this script successfully,you will get something like this :
Okay, Let me explain this how it works step by step:
The first step is to import Everything from Tkinter module of python.
Note: I am using 2.X.X version of python.For 3.x.x the module name has been changed. Just write ” tkinter ” (without Quotes) instead Tkinter. 🙂
Also Read : How To Use Python on Command Prompt
In the next step, I have created a variable called main assigned it to TK().For every Tk project first, we need to create this main to access the different widget classes inside the program.Here main is the parent window of the program.Whatever you wrote inside it,that will be displayed in that window only.So you should remember that this is mandatory for every program.
In the next line, we have to create a Label which typically has two or more parameters the first one is always for its root variable (main) and another parameter is used for different purposes.At present, we are using text parameter to write our text string and I have assigned the whole label to a variable called t.
Simply t.pack() method helps to fit the size of t Label to the root window.
Also Read : Python GUI Tkinter Tutorial Introduction
If you want your Tk will remain open until you close it then you should use the mainloop() method.This will keep looping the Tk window until you close it.
Hope It will work for you.Read all the articles in this category to understand Tk.
Please, Like Our Facebook Page For More Updates