Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_ui_font_size.py
- import Tkinter as tk
- import tkFont
- UI_SIZES = ["Tiny", "Small", "Normal", "Large", "Huge"]
- TINY_FONT_SIZE = 8
- SMALL_FONT_SIZE = 12
- NORMAL_FONT_SIZE = 16
- LARGE_FONT_SIZE = 18
- HUGE_FONT_SIZE = 24
- root = tk.Tk()
- ui_size = tk.StringVar(root, "Normal")
- entry_text = tk.StringVar(root, "Entry Text")
- def text_size_callback(*_args):
- """change the program font size when the font_size variable changes"""
- font = tkFont.nametofont("TkDefaultFont")
- selected_size = ui_size.get()
- if selected_size == "Tiny":
- font.configure(size=TINY_FONT_SIZE)
- elif selected_size == "Small":
- font.configure(size=SMALL_FONT_SIZE)
- elif selected_size == "Normal":
- font.configure(size=NORMAL_FONT_SIZE)
- elif selected_size == "Large":
- font.configure(size=LARGE_FONT_SIZE)
- elif selected_size == "Huge":
- font.configure(size=HUGE_FONT_SIZE)
- root.option_add("*Font", font)
- ui_size.trace('w', text_size_callback)
- ui_size.set("Normal")
- ui_radio_group = tk.Frame(root)
- ui_size_radios = []
- for sizeval in UI_SIZES:
- ui_size_radios.append(tk.Radiobutton(
- ui_radio_group,
- text=sizeval,
- variable=ui_size,
- value=sizeval
- ))
- text_entry = tk.Entry(ui_radio_group, textvariable=entry_text)
- i = 0
- for sizeradio in ui_size_radios:
- sizeradio.grid(row=i, column=0, sticky=tk.W)
- i += 1
- text_entry.grid(row=2, column=1)
- ui_radio_group.pack()
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement