Tkinter toplevel window adaptive size with screen - python

I'm trying to creat a python interface with tkinter.
The code is done on my laptop so every element's size (frame, label, entry, button, text font size, etc.) was created to fit my laptop's screen. I places all elements by grid.
But when i run the script on another computer with smaller screen size, i could not see the whole interface.
Is there any way in tkinter to automatically resize (reduce text size, frame size, entry size) to fit the interface to the screen size.
Thanks for your help!

Related

How to change the size of tkinter objects according to the display resolution

Hi I made the GUI of this program in 1980x1080 and everything is fit to the window, but when I run the program on the other pc of resolution 1366x768 3/4 of the GUI is outside the display.
This is my constructor for the GUI
class Main:
def __init__(self,master = None):
self.master = master
self.master.geometry(str(master.winfo_screenwidth())+'x' +str(master.winfo_screenheight()))
self.master.state('zoomed')
self.variables_for_graphs()
self.variables_for_inputer()
self.variables_for_graphs_menu()
self.place_frames()
screenshot of the program in 1980x1080 display resolution:
screenshot of the program in 1366x768 display resolution:
I add scaling to the constructor
dpi = master.winfo_fpixels('1i')
factor = dpi / 72
master.tk.call('tk', 'scaling', factor)
it did not help
if anything else is need please comment
you can multiply every dimension in your GUI by the ratio between the current resolution and the original resolution, but that would result in very ugly look, instead of manually setting the sizes of each object you should let tkinter size your objects.
for grid layout (similar to yours) you have. Tk Geometry manager
widget1.grid(row=0,column=0,rowspan=2,sticky="NWSE")
widget2.grid(row=0,column=1,sticky="NWSE")
widget3.grid(row=1,column=1,sticky="NWSE")
parent_widget.rowconfigure((0,1),weight=1,minsize=200)
parent_widget.columnconfigure((0,1),weight=1,minsize=200)
to set your widgets to grow to fill all its master space, with a minimum size of 400x400.
for widgets that you pack you should use
widget.pack(expand=True,fill="both")
which will also make the child grow to fill its parent space, the size system may look intimidating at first, but once you start using it you can get any shape you want with it that scales the way you want.
avoid using place as you have to manually manage its size (unless you have an object that must be of fixed size and position like a logo or floating widget), and avoid filling numbers for sizes yourself, things that you can fill yourself are probably padding, buttons size (sometimes), and font size (under different dpi), you should have tkinter manage other dimensions in your GUI otherwise your GUI won't scale well.

Managing size of multiple Tkinter Windows on display surface

How to manage the size of tkinter windows across many display of different sizes
For example in a device with resolution 1600x900 I have two adjacent windows with sizes 900x900 and 700x900(side to side)
from tkinter import *
root1=Tk()
root1.geometry("900x900")
root1.geometry("+0+0")
# some labels inside root1 with some width
root2=Tk()
root2.geometry("700x900")
root2.geometry("+900+0")
# some labels inside root2 window with width
root1.mainloop()
root2.mainloop()
If this code is used in a display with resolution 1300x900 some part of the second window gets hidden. I attempted to get resolution of device using root.winfo_screenwidth() and root.winfor_screenheight() but that doesn't solve the problem for managing the size of labels. So is there a way to shrink the whole window to an affordable size along with the labels, buttons and other things without affecting any position of labels.

How to scale image according to the pixel size of the screen in python

How can I scale the image or any widgets according to the pixel size of the screen using python?
I am using tkinter for making a GUI. Every time I change the pixel size of the screen it changes the place of the widgets on the screen.
Is there any builtin methods in tkinter for it.

PyGTK/Glade keep button size standard

I have a simple pygtk/glade window with a menu and a 3x3 grid. Each row of the grid consists on: two labels and a button.
When the Window is resized, the labels holds the same font size, but the buttons get resized, and they could become HUGE if the windows gets very big.
How could I manage to keep my buttons with the same size always (the "standar" size of a button, just like they are when the interface is just opened) no matter if the Window is resized?
You just have to set the fill and expand parameters of the Buttons to False (uncheck them in the Glade interface).
You would also want to put each button at the center of a 3x3 GtkTable, so it will appear centered and not aligned at the top of the cell

Resizing frames in Tkinter

I have been making a small program with the Tkinter module in python, and I was wondering whether it was possible or not to resize a frame in my program with the mouse. As in, the user can drag the frame border and it will resize itself.
Your use of terminology makes the question unclear. Windows which may be resized by the user are called Toplevel windows. These are what appear as rectangular windows on the display, with a frame around them, typically a title bar, and edges or corners that can be grabbed and resized.
The term Frame refers to a container widget that must be inside a Toplevel or one of its descendents. A Frame has the ability to be resized but you have to write the code to let you interactively resize them. For example, you could place a little grip widget in one or more corners, and writing bindings to the press, motion and release of a mouse button.
Depending on the effect you are looking for, you might want a PanedWindow which is a container that includes a sash that lets you adjust the proportion of space between two other widgets.

Categories