简体   繁体   中英

Changing font for four buttons at once in tkinter

Goal

I have created 4 buttons that are in the default font in Tkinter. Now I decided that all the four buttons are too small. So I want to increase the size of the font in them.

Problem faced

I don't want to add the thing font=custom where custom=tkFont.Font(family='Helvetica',size='18') in all the four statements.

Is there a way to do this for the whole frame that these buttons are there in?

code

f = self.frame
custom = Font(family='Helvetica',size=15)

start = Button(f,text='START',command=self.startrunning)


start.pack(side="top")


stop =Button(f,text='STOP',command=self.stoprunning)
stop.pack(side="top")

lap = Button(f,text='LAP',command=self.endlap)
lap.pack(side='top')

reset = Button(f,text="RESET",command = self.reset)
reset.pack(side="top")

close = Button(f,text="QUIT",bg="black",fg = "red",command=self.quitwin)
close.pack(side="top")

Please help me with some shortcut to achieve the goal. And if there is no shortcut please tell me that too!

buttons = [stop, lap, reset, close]
my_font = tkFont.Font(family='Helvetica',size='18')
for button in buttons:
    button.config(font=my_font)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM