问题
I want to use grid geometry to change the size of widget according to size of window(maximize or minimize).
Example:
If a window is made and its look fulfilled in minimize mode but on expanding it shows some blank space .I want to expand the widget in such a way to fulfill that blank space.
If the LCD is changed the window should look same.It should also manage its size according to different LCD size I used grid_rowconfigure and grid_columnconfigure methods, but in my program I am deleting one frame and then display another frame on that window...it works fine for the first frame but it doesn't work for the second frame and another problem is when I change my LCD screen to a smaller one, the widgets cannot be seen in a window as arranged in the bigger screen. The widget coincide with the border of window and some widgets disappear from window due to screen size.
回答1:
You will need to apply grid_rowconfigure() and grid_columnconfigure() on, respectively, the rows and columns of the parent/main widget where you draw the children widgets
.
Example:
Suppose on the main window you draw 2 buttons on the the first row and first 2 columns. You will need to apply the methods above like this:
main_window.grid_rowconfigure(0, weight=1) # For row 0
main_window.grid_columnconfigure(0, weight=1) # For column 0
main_window.grid_columnconfigure(1, weight=1) # For column 1
The columns
and rows
of the parent/main window
have a weight
grid option associated with them. This option, which is by default set 0 (don't expand to fill space), tells how much the row/column should grow if there is extra room in the master
to fill.
回答2:
Is this what you're looking for:
from tkinter import *
root = Tk()
label = Label(root, text="Hello world!", bg='cyan')
label.place(relwidth=0.5, relheight=0.5)
?
来源:https://stackoverflow.com/questions/38564649/adjust-widget-size-according-to-window-size-using-grid-geometry-and-screen-size