如何使用 Tkinter 在 python 中的框架内创建框架,然后在一个框架中打包一个按钮,当我按下按钮时,输出将在第二个框架上给出?
我们可以在一个框架内添加一个框架。下面的代码应该可以实现它。
import Tkinter
tk = Tkinter.Tk()
frame1 = Tkinter.Frame(tk, height = 100, width = 100, bg = "WHITE", borderwidth=2)
frame2 = Tkinter.Frame(frame1, height = 100, width = 100, bg = "RED", borderwidth=2)
frame1.pack()
frame2.pack()
label = Tkinter.Label(frame2, text = "Label") #Receive a callback from button here
label.pack()
button = Tkinter.Button(frame1,text="Button") #Send some action to Label here
button.pack()
tk.mainloop()
Run Code Online (Sandbox Code Playgroud)