当前位置:   article > 正文

python:tkinter实现点击跳转新窗口_tkinter点击按钮弹出新窗体

tkinter点击按钮弹出新窗体
import tkinter as tk
 
class Page_1:  # 这是第一个页面
    def __init__(self, window):
        self.window = window
        self.window.title("p1")
        self.window.geometry("200x200")
        self.window.config(bg="#F9C03D")
        self.button = tk.Button(self.window, text="跳转", command=self.change)
        self.button.pack()
 
    def change(self):
        # pass  # 不知道怎么写,先占位
        self.button.destroy()
        Page_2(root)
 
class Page_2:  # 这是第二个页面
    def __init__(self, window):
        self.window = window
        self.window.title("p2")
        self.window.geometry("300x300")
        self.window.config(bg="#0F375A")
        self.button = tk.Button(self.window, text="返回", command=self.back)
        self.button.pack()
 
 
    def back(self):
        # pass  # 不知道怎么写,先占位
        self.button.destroy()
        Page_1(root)
 
root = tk.Tk()
p1 = Page_1(root)  # 这两个页单,可单独运行
# p2 = Page_2(root)
root.mainloop()
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号