Advertisement
GamerBhai02

APP Exp 10

May 15th, 2025
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.46 KB | Source Code | 0 0
  1. import tkinter as tk
  2. from tkinter import messagebox
  3.  
  4. def on_button_click():
  5.     messagebox.showinfo("Button Clicked", "You clicked the button!")
  6.  
  7. def on_key_press(event):
  8.     label_event.config(text=f'Key Pressed: {event.char}', fg='red')
  9.    
  10. def change_color():
  11.     label_color.config(fg='green')
  12.    
  13. root = tk.Tk()
  14. root.title("GUI Demo - Fonts, Colors, Layouts, Events")
  15. root.geometry("500x400")
  16.  
  17. label1 = tk.Label(root, text="Pack Layout Example", font=("Arial", 14, "bold"), fg="blue")
  18. label1.pack(pady=10)
  19.  
  20. frame_grid = tk.Frame(root)
  21. frame_grid.pack(pady=10)
  22.  
  23. label_grid = tk.Label(frame_grid, text="Grid Layout:", font=("Times New Roman",12))
  24. label_grid.grid(row=0, column=0, padx=5)
  25.  
  26. entry_grid = tk.Entry(frame_grid, font=("Verdana",12))
  27. entry_grid.grid(row=0, column=1, padx=5)
  28.  
  29. label_place = tk.Label(root, text="Place Layout Example", font=("Comic Sans MS",12), fg="purple")
  30. label_place.place(x=180, y=120)
  31. label_place.pack(pady=10)
  32.  
  33. button_event = tk.Button(root, text="Click Me!", font=("Courier",12,"bold"), bg="yellow", command=on_button_click)
  34. button_event.pack(pady=10)
  35.  
  36. label_color = tk.Label(root, text="Change My Color", font=("Helvetica", 14))
  37. label_color.pack()
  38. button_color = tk.Button(root, text="Change Color", command=change_color)
  39. button_color.pack(pady=5)
  40.  
  41. label_event = tk.Label(root, text="Press Any Key", font=("Arial",12), fg="black")
  42. label_event.pack(pady=10)
  43. root.bind("<KeyPress>", on_key_press)
  44.  
  45. root.mainloop()
Tags: exp 10
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement