我不能在一个 tkinter 中使用两个框架 window

I can't use two frames in one tkinter window

我正在使用 tkinter 开发应用程序。我想在一个 window 中显示两个框架,一个框架在 window 的右侧,另一个框架在左侧。

with open("C:/gui_assistant/res/settings/frame_amount.txt", "r") as f:
     check_amount = f.read()

     if "one" in check_amount:
        one_frame = tk.Frame(main, bg="#1a1919", relief=SUNKEN)
        one_frame.place(relx=0.85, rely=0, relwidth=0.5, relheight=1)

    elif "two" in check_amount:
        first_frame = tk.Frame(main, bg="#1a1919", relief=SUNKEN)
        first_frame.place(relx=0.85, rely=0, relwidth=0.5, relheight=1)
        second_frame = tk.Frame(main, bg="#1a1919", relief=SUNKEN)
        second_frame.place(relx=0, rely=0, relwidth=0.5, relheight=1)

如您所知,它首先打开文本文件,然后检查给定的数量,因此如果文本文件显示“一个”,则只应创建一帧,如果是“二”,则应创建两帧应该创建。现在,文本文件显示“两个”,但在 运行 应用程序之后只创建了一个框架。 Tkinter 是否只允许 window 中的 1 帧?,orrr...

试试这个

from tkinter import *
main = Tk()
main.config(background='red')
def check():
    with open("frame_amount.txt", "r") as f:
        check_amount = f.read()
        s_w= int(main.winfo_width())
        s_h= int(main.winfo_height())
        if "one" in check_amount:
            one_frame = Frame(main,background='green')
            one_frame.place(x=0, y=0, width=s_w, height=s_h)

        elif "two" in check_amount:
            first_frame = Frame(main,background='blue')
            first_frame.place(x=0, y=0, width=s_w//2, height=s_h)
            second_frame = Frame(main,background='black')
            second_frame.place( x=s_w // 2, y= 0, width=s_w//2, height=s_h)
        b = Button(main,text='chack',command=check)
        b.place(x=1,y=1)
b = Button(main,text='chack',command=check)
b.place(x=1,y=1)

main.mainloop()