Programming Code Examples

Tkinter “Hello World” in Python 31 min read

In this example, I’ll create a hello world application using Tkinter in Python 3.

Output:

Tkinter "Hello World" in Python 3
Tkinter “Hello World” in Python 3




Python 3 Code:

Download hello world python tkinter

This code creates a simple graphical user interface (GUI) using the Tkinter library in Python. Here is a breakdown of what the code does:

  1. The first two lines import the Tkinter library and create a Tk object called window, which represents the main window of the GUI.
  2. The title method sets the title of the window to “www.code4example.net“, and the geometry method sets the size of the window to 400 pixels wide and 200 pixels tall.
  3. A Frame object called app is created, which will contain the other widgets (elements) of the GUI. The grid method is called to set up a grid layout for the widgets.
  4. A Label widget called w is created, which displays the text “Hello, world!” in a large, Courier font. The grid method is called to position the label within the app frame.
  5. The mainloop method is called to start the GUI event loop, which listens for user input and updates the GUI as necessary.

When the code is run, it will create a window with a label that says “Hello, world!” in a large, Courier font. The window will remain open until the user closes it.

Add comment