Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tkinter as tk
- from tkinter import messagebox
- def on_button_click():
- messagebox.showinfo("Button Clicked", "You clicked the button!")
- def on_key_press(event):
- label_event.config(text=f'Key Pressed: {event.char}', fg='red')
- def change_color():
- label_color.config(fg='green')
- root = tk.Tk()
- root.title("GUI Demo - Fonts, Colors, Layouts, Events")
- root.geometry("500x400")
- label1 = tk.Label(root, text="Pack Layout Example", font=("Arial", 14, "bold"), fg="blue")
- label1.pack(pady=10)
- frame_grid = tk.Frame(root)
- frame_grid.pack(pady=10)
- label_grid = tk.Label(frame_grid, text="Grid Layout:", font=("Times New Roman",12))
- label_grid.grid(row=0, column=0, padx=5)
- entry_grid = tk.Entry(frame_grid, font=("Verdana",12))
- entry_grid.grid(row=0, column=1, padx=5)
- label_place = tk.Label(root, text="Place Layout Example", font=("Comic Sans MS",12), fg="purple")
- label_place.place(x=180, y=120)
- label_place.pack(pady=10)
- button_event = tk.Button(root, text="Click Me!", font=("Courier",12,"bold"), bg="yellow", command=on_button_click)
- button_event.pack(pady=10)
- label_color = tk.Label(root, text="Change My Color", font=("Helvetica", 14))
- label_color.pack()
- button_color = tk.Button(root, text="Change Color", command=change_color)
- button_color.pack(pady=5)
- label_event = tk.Label(root, text="Press Any Key", font=("Arial",12), fg="black")
- label_event.pack(pady=10)
- root.bind("<KeyPress>", on_key_press)
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement