Python - quick tkinter example


Python tip:

You can use tkinter to build simple desktop applications

An example👇

import tkinter as tk


class Application(tk.Frame):
    def __init__(self, master=None):
        self.number_of_clicks = tk.IntVar(value=0)

        super().__init__(master)
        self.master = master
        self.pack()
        self.create_widgets()

    def create_widgets(self):
        self.number_of_clicks_value = tk.Label(self, textvariable=self.number_of_clicks)
        self.number_of_clicks_value.pack(side="top")

        self.click_me = tk.Button(self, text="Click me", command=self.increment)
        self.click_me.pack(side="top")

        self.quit = tk.Button(self, text="QUIT", fg="red", command=self.master.destroy)
        self.quit.pack(side="bottom")

    def increment(self):
        self.number_of_clicks.set(self.number_of_clicks.get() + 1)


root = tk.Tk()
app = Application(master=root)
app.mainloop()