Я наткнулся на блокпост на одной из моих программ. Ниже мой код. Я создал приложение окна tkinter с несколькими кадрами. Я смог правильно их настроить, с рамками внутри рамок. Тем не менее, я застрял на том, чтобы не знать, почему добавление виджета метки изменяет размер фрейма. Предложения будут оценены.
В следующем коде обратите внимание на разницу между раскомментированием пары виджетов с метками.
import tkinter as tk
def main():
print ('Beginning')
app = tk.Tk()
size_x = app.winfo_screenwidth()
size_y = app.winfo_screenheight()
app.title('Color Mixer')
app.geometry("%dx%d+0+0" % (size_x, size_y))
# This disables resizing windows.
#app.configure(background = 'yellow')
print ('Beginning')
#Main containers
top_frame = tk.Frame(app, bg = 'yellow', width=size_x, height=int(size_y/3), padx = 3, pady=3)
bottom_frame = tk.Frame(app, bg='green', width=size_x, height=int(2*size_y/3), padx=3, pady=3)
# layout all of the main containers
app.grid_rowconfigure(0, weight=1)
app.grid_columnconfigure(0, weight=1)
top_frame.grid(row=0, sticky="nsew")
bottom_frame.grid(row=1, sticky="nsew")
# create the widgets for the top frame
model_label = tk.Label(top_frame, font = ('Times', str(int(size_x*0.014)), 'bold'), bg = 'yellow' , text='Pick a Color Model')
model_label.grid(row=0, column = 0)
v = tk.IntVar()
tk.Radiobutton(top_frame,
text="RYB Color Space",
indicatoron=0,
padx=35,
font=('Times',str(int(size_x * 0.0075)), 'normal'),
variable=v,
value=1).grid(row=1, column=0)
tk.Radiobutton(top_frame,
text="CMYK Color Space",
indicatoron=0,
padx=20,
font=('Times', str(int(size_x * 0.0075)), 'normal'),
variable=v,
value=2).grid(row=2, column=0)
top_frame.grid_rowconfigure(0, weight=1)
top_frame.grid_rowconfigure(1, weight=1)
top_frame.grid_rowconfigure(2, weight=1)
top_frame.grid_columnconfigure(0, weight = 1)
# Bottom Frame - Dividing into two frames.
bottom_left = tk.Frame(bottom_frame, bg='blue', width=int(0.5*size_x), height=int(2/3*size_y), padx = 3, pady =3)
bottom_right = tk.Frame(bottom_frame, bg='red', width=int(0.5*size_x), height=int(2/3*size_y), padx=3, pady=3)
bottom_left.grid(row=0, column=0, sticky="nsew")
bottom_right.grid(row=0, column=1, sticky="nsew")
# ryb_note = tk.Label(bottom_left, font=('Times', str(int(size_x * 0.005)), 'normal'), bg='red', text='NOTE')
# ryb_note.grid(row=0, column=0)
# ryb_red = tk.Label(bottom_left, font=('Times', str(int(size_x * 0.005)), 'normal'), bg='red', text='Red')
# ryb_red.grid(row=1, column=0)
bottom_frame.grid_rowconfigure(0, weight = 1)
bottom_frame.grid_columnconfigure(0, weight = 1)
bottom_frame.grid_columnconfigure(1, weight = 1)
app.mainloop()
if __name__ == '__main__':
main()