Advertisement
FanaticExplorer

tkinter_width_problem

Apr 21st, 2023
685
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.13 KB | None | 0 0
  1. import tkinter as tk
  2. import tkinter.ttk as ttk
  3.  
  4. links_conf = tk.Tk()
  5. links_conf.title("Links configurer")
  6. links_conf['bg']='white'
  7. links_conf.iconbitmap("Link.ico")
  8. links_conf.minsize(350, 100)
  9. # links_conf.geometry('300x200')
  10.  
  11. frame1 = tk.Frame(master=links_conf, width=200, height=100, bg="white")
  12. frame1.pack(fill=tk.BOTH, side=tk.LEFT, expand=True)
  13. frame2 = tk.Frame(master=links_conf, width=100, bg="white")
  14. frame2.pack(fill=tk.BOTH, side=tk.LEFT, expand=True)
  15. frame3 = tk.Frame(master=links_conf, width=50, bg="white")
  16. frame3.pack(fill=tk.BOTH, side=tk.LEFT, expand=True)
  17.  
  18.  
  19. combobox = ttk.Combobox(master=frame1)
  20. combobox['values'] = ['Hello', 'World']
  21. combobox['state'] = 'normal'
  22. def resize_combobox(event):
  23.     frame_width = event.width
  24.     combobox.config(width=int(frame_width/2))
  25. frame1.bind("<Configure>", resize_combobox)
  26. combobox.place(relx=0.5, rely=0.5, anchor=tk.CENTER)
  27.  
  28. entry = tk.Entry(master=frame2, bg="white", width=50)
  29. entry.place(relx=0.5, rely=0.5, anchor=tk.CENTER)
  30.  
  31. button = tk.Button(text="Click me!", master=frame3)
  32. button.place(relx=0.5, rely=0.5, anchor=tk.CENTER)
  33.  
  34. links_conf.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement