How can i fit my tkinter app to any size screen?
im doing an tkinter app in a computer, im using the grid() method to place the widgets. At first of the program i use this code to make the window size like the screen size:
an = self.root.winfo_screenwidth()
al = self.root.winfo_screenheight()
self.tam = '%dx%d'%(an,al)
self.root.geometry(self.tam)
And it works, but this app will be used through a remote desktop with different devices (different screen sizes). How can I do that the widgets fill on the window like the original design? Thanks
Solution 1:
Without any concrete examples of your code, there's no way to give more specific advice than to say that the solution is to design your program so that it resizes well.
Tkinter excels at making widgets fit, so as long as you use the options at your disposal (fill
and expand
for pack
, row and column weights and other options for grid
), and you don't hard-code any widths and heights, your GUI will easily work on a variety of systems.
Concrete pieces of advice:
- don't use
place
except in very rare circumstances. Whileplace
supports relative positioning and sizing, it requires more work thanpack
andgrid
- design the GUI to work on the smallest display possible, and then make sure that when you manually resize the window it behaves properly
- When using
grid
, make sure you always have at least one row and one column with a non-zero weight so that it knows how to allocate extra space - When using
pack
make sure you useexpand
andfill
properly - Don't turn off the ability for the user to resize the window