Your first Python GUI program
As we discussed in an earlier chapter, the first program while learning any programming language includes printing Hello World!
. Now, as we are starting Python programming for GUI, let's start by printing the same string in a GUI window instead of a prompt.
Just to start with GUI programming, we are going to execute a Python program and then jump into explaining the structure and the details of the code. Let's create a Python executable file using the following lines of code, name it helloGUI.py
, and then run it. The execution process should complete without any dependency errors:
import Tkinter # Initialize main windows with title and size top = Tkinter.Tk() top.title("Hello GUI") top.minsize(200,30) # Label widget helloLabel = Tkinter.Label(top, text = "Hello World!") helloLabel.pack() # Start and open the window top.mainloop()
You should be prompted with the following window on the successful execution of the preceding code snippet. As you can see, the Hello...