所以基本上我是用Tkinter制作GUI的。我也想在Tkinter窗口中制作一个框架,当我单击按钮时它应该会打开。
到目前为止,这是我的代码:
from tkinter import *
import tkinter
screen = Tk()
screen.title("My GUI")
screen.geometry("600x600")
screen.configure(background="Gray")
button1 = Button(screen)
button.pack()
screen.mainloop
那么当我单击按钮时如何创建新窗口(框架)?
答案 0 :(得分:0)
您可以按照以下逻辑创建/切换框架
from tkinter import *
import tkinter
screen = Tk()
screen.title("My GUI")
screen.geometry("600x600")
screen.configure(background="Gray")
frame_enabled = False
def toggle_frame():
global frame_enabled
if not frame_enabled:
my_frame.pack(fill='both', expand=True)
else:
my_frame.pack_forget()
frame_enabled = not frame_enabled
button1 = Button(screen, text="Toggle frame", command=toggle_frame)
button1.pack()
my_frame = Frame(screen, bg="red")
screen.mainloop()