Python 3 Tkinter GUI Hello World Program

By | March 22, 2020


Topic: Python 3 Tkinter GUI Hello World Program

# Write a Python GUI program
# using tkinter module
# to diplay a window
# with title "Hello World"

import tkinter as tk

def main():
    window= tk.Tk()
    window.title("Hello World")

    window.mainloop()

main()

Output:

Python 3 Tkinter GUI Hello World Program

Python 3 Tkinter GUI Hello World Program

But we find that the title is not completely shown. Therefore we will add one more line of Python code to set (increase) size of the main window.

# Write a Python GUI program
# using tkinter module
# to diplay a window
# with title "Hello World"

import tkinter as tk

def main():
    window= tk.Tk()
    window.title("Hello World")
    window.geometry("400x200")

    window.mainloop()

main()

Here we have given the size dimentions to the main window 400×200 using geometry() method.

Output:

Python Tkinter GUI Program Hello World

Python Tkinter GUI Program Hello World