Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

How to put tkinter buttons in a list?

How can I put tkinter buttons into a list that way I can resize every button when I change the window size rather than creating a window change size for every button I have?



list = (btn1, btn2)

def resize(e):
    size = e.width / 10
    list.config(font=('Times', int(size)))

btn1 = Button()
btn2 = Button()

root.bind('<Configure>', resize)


Link to post
Share on other sites

You've done it already pretty much. A few points:

  1. list is a Python keyword and those should never be used as variable names.
  2. You have defined your list with ( ), which makes it a tuple. If you want a list define it with [ ].

Haven't used Tkinter, but you can then probably just loop over the list of buttons and bind the resize method to it?

Crystal: CPU: i7 7700K | Motherboard: Asus ROG Strix Z270F | RAM: GSkill 16 GB@3200MHz | GPU: Nvidia GTX 1080 Ti FE | Case: Corsair Crystal 570X (black) | Storage: 250 GB Crucial BX100 SSD + 2 TB Seagate HDD + 1TB WD Green + 3TB WD Red | PSU: EVGA Supernova G2 1000W | Monitor: Asus VG248QE 24"

Laptop: Dell XPS 13 9370 | CPU: i5 10510U | RAM: 16 GB

Link to post
Share on other sites

I did what you said but it is saying one of the items in the list is not defined.

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now