python tkinter basics code example
Example 1: tkinter basic
from tkinter import Tk, Label, Button
class MyFirstGUI:
def __init__(self, master):
self.master = master
master.title("A simple GUI")
self.label = Label(master, text="This is our first GUI!")
self.label.pack()
self.greet_button = Button(master, text="Greet", command=self.greet)
self.greet_button.pack()
self.close_button = Button(master, text="Close", command=master.quit)
self.close_button.pack()
def greet(self):
print("Greetings!")
root = Tk()
my_gui = MyFirstGUI(root)
root.mainloop()
Example 2: tkinter tutorial
from tkinter import *
app = Tk()
app.title("The title of the project")
app.geometry("400x400")
def c():
m = Label(app, text="Text")
m.pack()
l = Button(app, text="The text of the Butoon", command=c)
l.pack()
app.mainloop()
Example 3: tkinter python tutorial
button = tk.Button(
text="Click me!",
width=25,
height=5,
bg="blue",
fg="yellow",
)
Example 4: tkinter tutorial
import tkinter as tk
window = tk.Tk()
frame_a = tk.Frame()
frame_b = tk.Frame()
label_a = tk.Label(master=frame_a, text="I'm in Frame A")
label_a.pack()
label_b = tk.Label(master=frame_b, text="I'm in Frame B")
label_b.pack()
frame_a.pack()
frame_b.pack()
window.mainloop()
Example 5: tkinter tutorial
text_box.insert(tk.END, "Put me at the end!")