Jump to content

How to put tkinter buttons in a list?

Enderg312

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?

 

eg.

list = (btn1, btn2)

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

btn1 = Button()
btn2 = Button()
btn1.grid()
btn2.grid()

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

 

Link to comment
Share on other sites

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) | PSU: EVGA Supernova G2 1000W | Monitor: Asus VG248QE 24"

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

Server: CPU: i5 4690k | RAM: 16 GB | Case: Corsair Graphite 760T White | Storage: 19 TB

Link to comment
Share on other sites

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 comment
Share on other sites

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

×