0
global my_frame
my_frame = Frame(tab2, bg="white")
my_frame.place(relwidth= 0.81, relheight= 0.8, relx=0.1, rely=0.1,)

text_scroll = Scrollbar(my_frame)
text_scroll.pack(side=RIGHT, fill=Y)

the text entry

global textbox
textbox = Text(my_frame,undo=True,font=12, yscrollcommand=text_scroll.set)
textbox.place(relwidth= 0.985, relheight= 1, relx=0, rely=0)

text_scroll.config(command=textbox.yview)

the dropdown menu i want to be able to select the font

clicked = StringVar()
clicked.set(12)

drop = OptionMenu(tab2,clicked, 1,2,3,4,5,6,7,8,9,10,11,12,13,14)
drop.pack()

My problem is i dont know how to say to the text size to set deppending on what number the user did select. Please help.

Fovu
  • 71
  • 6
  • Use `clicked.trace("w", callback)` and in the `callback` function use `clicked.get()` to get what is in the `OptionMenu`. After that you can just use `textbox.config(font=)` – TheLizzard Apr 06 '21 at 11:22

1 Answers1

0

Try this:

import tkinter as tk

def callback(*args):
    new_font_size = int_var.get()
    text_widget.config(font=("", new_font_size))

root = tk.Tk()

text_widget = tk.Text(root, font=("", 12))
text_widget.pack()

int_var = tk.IntVar(root)
int_var.trace("w", callback)
drop = tk.OptionMenu(root, int_var, *range(1, 15))
drop.pack()

root.mainloop()

I change the variable from tk.StringVar to tk.IntVar because we are dealing with ints. Also the font argument should be a tuple like this: ("<font family name>", <font size>).

I am tracing what the int_var value is and updating the text_widget accordingly.

TheLizzard
  • 7,248
  • 2
  • 11
  • 31