tkinter Getting started with tkinter Hello, World! (modular, object-oriented)

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

import tkinter as tk

class HelloWorld(tk.Frame):
    def __init__(self, parent):
        super(HelloWorld, self).__init__(parent)

        self.label = tk.Label(self, text="Hello, World!")
        self.label.pack(padx=20, pady=20)
        
if __name__ == "__main__":
    root = tk.Tk()

    main = HelloWorld(root)
    main.pack(fill="both", expand=True)

    root.mainloop()

Note: It's possible to inherit from just about any tkinter widget, including the root window. Inheriting from tkinter.Frame is at least arguably the most flexible in that it supports multiple document interfaces (MDI), single document interfaces (SDI), single page applications, and multiple-page applications.



Got any tkinter Question?