Advertisement
here2share

# Tk_change_titlebar.py

Dec 29th, 2021
1,220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.02 KB | None | 0 0
  1. # Tk_change_titlebar.py
  2.  
  3. from tkinter import *
  4.  
  5. root = Tk()
  6. root.title('Change Titlebar')
  7. # root.iconbitmap('c:/your.ico')
  8.  
  9. ww = 500
  10. hh = 300
  11.  
  12. root.geometry(f'{ww}x{hh}+10+10')
  13.  
  14. # remove title bar
  15. root.overrideredirect(True)
  16.  
  17. def move_app(e):
  18.     root.geometry(f'{ww}x{hh}+{e.x_root-int(ww/2)}+{e.y_root-10}')
  19.  
  20. def quitter(e=None):
  21.     root.destroy()
  22.  
  23. # Create Fake Title Bar
  24. title_bar = Frame(root, bg="darkgreen", relief="raised", bd=0)
  25. title_bar.pack(expand=1, fill=X)
  26. # Bind the titlebar
  27. title_bar.bind("<B1-Motion>", move_app)
  28.  
  29. # Create title text
  30. title_label = Label(title_bar, text="  My Awesome App!", bg="darkgreen", fg="white")
  31. title_label.pack(side=LEFT, pady=4)
  32.  
  33. # Create close button on titlebar
  34. close_label = Label(title_bar, text="  X  ", bg="yellow", fg="red", relief="sunken", bd=1)
  35. close_label.pack(side=RIGHT, padx=3, pady=1)
  36. close_label.bind("<Button-1>", quitter)
  37.  
  38. my_button = Button(root, text="CLOSE!", font=("Helvetica, 32"), command=quitter)
  39. my_button.pack(pady=100)
  40.  
  41. root.mainloop()
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement