So I made a script a small function which adds a 1 to the int x and used it in the text box for the size the problem is that the text box doesn't read the new size of the font after i launch the function so how do i refresh the text box for it to use the latest x value?
import re
from tkinter import *
from tkinter import ttk
import time
root = Tk()
root.title('Notepad')
root.iconbitmap('C:/Users/Hero/Documents/Visual Studio code/My project/notes.ico')
root.geometry("500x500")
root.tk.call("source", "C:/Users/Hero/Documents/Visual Studio code/My project/azure.tcl")
root.tk.call("set_theme", "dark")
global x
x = 20
def change_theme():
if root.tk.call("ttk::style", "theme", "use") == "azure-dark":
root.tk.call("set_theme", "light")
else:
root.tk.call("set_theme", "dark")
def font_size():
global x
x = x 1
print(x)
text=Text(root, font=("Georgia", x), yscrollcommand=scroll.set, bg='#292929', height=1, width=1)
style=ttk.Style()
style.theme_use('azure-dark')
style.configure("Vertical.TScrollbar", background="grey", bordercolor="black", arrowcolor="white")
barframe = Frame()
barframe.pack(side=BOTTOM)
fonts = ttk.Button(barframe, text='Size and Font', width=15, style='Accent.TButton', command=font_size)
calculater = ttk.Button(root, text='Calculater', width=15, style='Accent.TButton')
fonts.grid(row=0, column=0)
scroll = ttk.Scrollbar(root, orient='vertical')
scroll.pack(side=RIGHT, fill='y')
text=Text(root, font=("Georgia", x), yscrollcommand=scroll.set, bg='#292929', height=1, width=1)
scroll.config(command=text.yview)
text.pack(fill=BOTH, expand=1)
root.mainloop()
CodePudding user response:
Instead of text = Text(...)
in your font_size
function, which creates a new Text
, you want to update the one that already exists.
text.config(font=("Georgia", x))
CodePudding user response:
for change parameter must be used method config
or itemconfig
label=Label(text="hello world")
label.config(text="hello")