Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tkinter as tk
- import tkinter.ttk as ttk
- import tkinter.font as tkfont
- root = tk.Tk()
- root.rowconfigure(0, weight=1)
- root.columnconfigure(99, weight=1)
- style = ttk.Style(root)
- def resize(ev):
- wdg = ev.widget
- def func():
- size = wdg.get() # get current spinbox's value
- font1.configure(size=size)
- font2.configure(size=size)
- for e in entries: # update font in all entries
- e.configure(font=font2)
- root.after(0, func)
- style.layout(
- 'resize1.TSpinbox', [(
- 'Spinbox.field', {
- 'expand': 1,
- 'sticky': tk.NSEW,
- 'children': [(
- 'null', {
- 'side': 'right',
- 'sticky': 'ns',
- 'children': [(
- 'Spinbox.uparrow', {
- 'side': 'top', 'sticky': 'e'
- }
- ), (
- 'Spinbox.downarrow', {
- 'side': 'bottom', 'sticky': 'e'
- }
- )]
- }
- ), (
- 'Spinbox.padding', {
- 'sticky': tk.NSEW,
- 'children': [(
- 'Spinbox.textarea', {
- 'sticky': tk.NSEW
- }
- )]
- }
- )]
- })
- ])
- style.layout(
- 'resize2.TSpinbox', [(
- 'Spinbox.field', {
- 'expand': 1,
- 'sticky': tk.NSEW,
- 'children': [(
- 'null', {
- 'side': 'right',
- 'sticky': 'e',
- 'children': [(
- 'Spinbox.uparrow', {
- 'side': 'top', 'sticky': 'e'
- }
- ), (
- 'Spinbox.downarrow', {
- 'side': 'bottom', 'sticky': 'e'
- }
- )]
- }
- ), (
- 'Spinbox.padding', {
- 'sticky': tk.NSEW,
- 'children': [(
- 'Spinbox.textarea', {
- 'sticky': tk.NSEW
- }
- )]
- }
- )]
- })
- ])
- frame = ttk.Frame(root)
- frame.rowconfigure(0, weight=1)
- frame.columnconfigure(0, weight=1)
- entries = [] # list of all entries
- font1 = tkfont.nametofont('TkDefaultFont')
- font2 = tkfont.nametofont('TkTextFont')
- cbo = ttk.Combobox(frame)
- entries.append(cbo)
- cbo.config(values=('Test 1', 'Test 2', 'Test 3'))
- cbo.set(value='Test 1')
- ent_var = tk.StringVar()
- ent = ttk.Entry(frame, textvariable=ent_var)
- entries.append(ent)
- ent_var.set('Testing')
- spn_var = tk.IntVar()
- spn_var.set(font1.actual()['size'])
- spn = ttk.Spinbox(frame, textvariable=spn_var, values=tuple(range(1, 101)), style='resize1.TSpinbox')
- entries.append(spn)
- spn.bind('<<Increment>>', resize)
- spn.bind('<<Decrement>>', resize)
- spn2_var = tk.IntVar()
- spn2_var.set(font1.actual()['size'])
- spn2 = ttk.Spinbox(frame, textvariable=spn2_var, values=tuple(range(1, 101)), style='resize2.TSpinbox')
- entries.append(spn2)
- spn2.bind('<<Increment>>', resize)
- spn2.bind('<<Decrement>>', resize)
- lbl_field_name = ttk.Label(frame, text='Field Name')
- lb_size = ttk.Label(frame, text='Font Size')
- lbl_field_name.grid()
- cbo.grid(row=0, column=1, sticky=tk.NSEW)
- ent.grid(row=0, column=2, sticky=tk.NSEW)
- lb_size.grid(row=0, column=3, sticky=tk.NSEW)
- spn.grid(row=0, column=4, sticky=tk.NSEW)
- spn2.grid(row=0, column=5, sticky=tk.NSEW)
- frame.grid(sticky=tk.NSEW)
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement