Tkinter 实现单击按钮导航到指定窗口,并要求内嵌主窗口下显示或实现类似效果
import tkinter as tk
from tkinter import Toplevel
def open_window1():
window = Toplevel(root)
window.title(“窗口1”)
window.geometry(“400x300”) # 窗口大小
label = tk.Label(window, text=”这是窗口1的内容”)
label.pack()
def open_window2():
window = Toplevel(root)
window.title(“窗口2”)
window.geometry(“400x300”) # 窗口大小
label = tk.Label(window, text=”这是窗口2的内容”)
label.pack()
def open_window3():
window = Toplevel(root)
window.title(“窗口3”)
window.geometry(“400x300”) # 窗口大小
label = tk.Label(window, text=”这是窗口3的内容”)
label.pack()
root = tk.Tk()
root.title(“主窗口”)
root.geometry(“400x300”) # 窗口大小
button1 = tk.Button(root, text=”按钮1”, command=open_window1)
button1.grid(row=1, column=1, columnspan=2, padx=5, pady=5)
button2 = tk.Button(root, text=”按钮2”, command=open_window2)
button2.grid(row=1, column=3, columnspan=2, padx=5, pady=5)
button3 = tk.Button(root, text=”按钮3”, command=open_window3)
button3.grid(row=1, column=5, columnspan=2, padx=5, pady=5)
root.mainloop()