install tkinter python3 code example

Example 1: install tkinter

pip3 install tk

Example 2: how to install tkinter

sudo apt-get install python3-tk

Example 3: how to install tkinter for python

# for pip and windows, in cmd, write:
pip install tk

Example 4: pip install tkinter

pip install tk

Example 5: tkinter python 3

import tkinter as tk

obj = tk.Tk() # Creates a tkinter object
label = tk.Label(obj, text="This is a text button")

Example 6: tkinter python3

import tkinter as tk

class Application(tk.Frame):
    def __init__(self, master=None):
        super().__init__(master)
        self.master = master
        self.pack()
        self.create_widgets()

    def create_widgets(self):
        self.hi_there = tk.Button(self)
        self.hi_there["text"] = "Hello World\n(click me)"
        self.hi_there["command"] = self.say_hi
        self.hi_there.pack(side="top")

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

    def say_hi(self):
        print("hi there, everyone!")

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