{"id":1033031,"date":"2024-12-31T11:38:26","date_gmt":"2024-12-31T03:38:26","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1033031.html"},"modified":"2024-12-31T11:38:28","modified_gmt":"2024-12-31T03:38:28","slug":"python%e5%a6%82%e4%bd%95%e5%81%9a%e7%aa%97%e5%8f%a3%e4%b9%8b%e9%97%b4%e7%9a%84%e8%b7%b3%e8%bd%ac","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1033031.html","title":{"rendered":"Python\u5982\u4f55\u505a\u7a97\u53e3\u4e4b\u95f4\u7684\u8df3\u8f6c"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2024\/12\/7ca9ee77-f532-410c-9aa6-4f53b8d5f0f3.webp?x-oss-process=image\/auto-orient,1\/format,webp\" alt=\"Python\u5982\u4f55\u505a\u7a97\u53e3\u4e4b\u95f4\u7684\u8df3\u8f6c\" \/><\/p>\n<p><p> <strong>Python\u7a97\u53e3\u4e4b\u95f4\u7684\u8df3\u8f6c\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528GUI\u5e93\u5982Tkinter\u3001PyQt\u3001Kivy\u6765\u5b9e\u73b0\uff0c\u901a\u8fc7\u5728\u4e0d\u540c\u7a97\u53e3\u4e4b\u95f4\u5207\u6362\u3001\u9690\u85cf\u548c\u663e\u793a\u7a97\u53e3\u6765\u5b9e\u73b0\u8df3\u8f6c\u3002\u5176\u4e2d\uff0cTkinter\u662fPython\u7684\u6807\u51c6GUI\u5e93\uff0c\u7b80\u5355\u6613\u7528\uff0c\u9002\u5408\u521d\u5b66\u8005\uff1bPyQt\u529f\u80fd\u5f3a\u5927\uff0c\u9002\u5408\u590d\u6742\u7684GUI\u5e94\u7528\u5f00\u53d1\uff1bKivy\u9002\u5408\u5f00\u53d1\u8de8\u5e73\u53f0\u5e94\u7528\u3002<\/strong> \u4e0b\u9762\u6211\u4eec\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528Tkinter\u6765\u5b9e\u73b0\u7a97\u53e3\u4e4b\u95f4\u7684\u8df3\u8f6c\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001Tkinter\u5b9e\u73b0\u7a97\u53e3\u8df3\u8f6c<\/h3>\n<\/p>\n<p><p>Tkinter\u662fPython\u5185\u7f6e\u7684\u6807\u51c6GUI\u5e93\uff0c\u9002\u7528\u4e8e\u5feb\u901f\u5f00\u53d1\u684c\u9762\u5e94\u7528\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528Tkinter\u521b\u5efa\u591a\u4e2a\u7a97\u53e3\uff0c\u5e76\u901a\u8fc7\u6309\u94ae\u89e6\u53d1\u4e8b\u4ef6\u6765\u5b9e\u73b0\u7a97\u53e3\u4e4b\u95f4\u7684\u8df3\u8f6c\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u521b\u5efa\u4e3b\u7a97\u53e3\u548c\u5b50\u7a97\u53e3<\/h4>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u6211\u4eec\u521b\u5efa\u4e00\u4e2a\u4e3b\u7a97\u53e3\u548c\u4e00\u4e2a\u5b50\u7a97\u53e3\uff0c\u4e3b\u7a97\u53e3\u5305\u542b\u4e00\u4e2a\u6309\u94ae\uff0c\u5f53\u70b9\u51fb\u6309\u94ae\u65f6\uff0c\u6253\u5f00\u5b50\u7a97\u53e3\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import tkinter as tk<\/p>\n<p>def open_child_window():<\/p>\n<p>    child_window = tk.Toplevel(root)<\/p>\n<p>    child_window.title(&quot;\u5b50\u7a97\u53e3&quot;)<\/p>\n<p>    label = tk.Label(child_window, text=&quot;\u8fd9\u662f\u5b50\u7a97\u53e3&quot;)<\/p>\n<p>    label.pack()<\/p>\n<p>root = tk.Tk()<\/p>\n<p>root.title(&quot;\u4e3b\u7a97\u53e3&quot;)<\/p>\n<p>button = tk.Button(root, text=&quot;\u6253\u5f00\u5b50\u7a97\u53e3&quot;, command=open_child_window)<\/p>\n<p>button.pack()<\/p>\n<p>root.m<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>nloop()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u5b9a\u4e49\u4e86\u4e00\u4e2a\u51fd\u6570<code>open_child_window<\/code>\uff0c\u8be5\u51fd\u6570\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u9876\u7ea7\u7a97\u53e3\uff08\u5b50\u7a97\u53e3\uff09\uff0c\u5e76\u5728\u5176\u4e2d\u653e\u7f6e\u4e00\u4e2a\u6807\u7b7e\u3002\u4e3b\u7a97\u53e3\u5305\u542b\u4e00\u4e2a\u6309\u94ae\uff0c\u5f53\u70b9\u51fb\u6309\u94ae\u65f6\uff0c\u8c03\u7528<code>open_child_window<\/code>\u51fd\u6570\uff0c\u4ece\u800c\u6253\u5f00\u5b50\u7a97\u53e3\u3002<\/p>\n<\/p>\n<p><h4>2\u3001\u5728\u591a\u4e2a\u7a97\u53e3\u4e4b\u95f4\u8df3\u8f6c<\/h4>\n<\/p>\n<p><p>\u4e3a\u4e86\u5728\u591a\u4e2a\u7a97\u53e3\u4e4b\u95f4\u8df3\u8f6c\uff0c\u6211\u4eec\u53ef\u4ee5\u5728\u6bcf\u4e2a\u7a97\u53e3\u4e2d\u653e\u7f6e\u6309\u94ae\u6765\u5173\u95ed\u5f53\u524d\u7a97\u53e3\u5e76\u6253\u5f00\u53e6\u4e00\u4e2a\u7a97\u53e3\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import tkinter as tk<\/p>\n<p>def open_window_a():<\/p>\n<p>    window_a = tk.Toplevel(root)<\/p>\n<p>    window_a.title(&quot;\u7a97\u53e3 A&quot;)<\/p>\n<p>    button = tk.Button(window_a, text=&quot;\u6253\u5f00\u7a97\u53e3 B&quot;, command=lambda: open_window_b(window_a))<\/p>\n<p>    button.pack()<\/p>\n<p>def open_window_b(previous_window):<\/p>\n<p>    previous_window.destroy()<\/p>\n<p>    window_b = tk.Toplevel(root)<\/p>\n<p>    window_b.title(&quot;\u7a97\u53e3 B&quot;)<\/p>\n<p>    button = tk.Button(window_b, text=&quot;\u56de\u5230\u4e3b\u7a97\u53e3&quot;, command=lambda: open_main_window(window_b))<\/p>\n<p>    button.pack()<\/p>\n<p>def open_main_window(previous_window):<\/p>\n<p>    previous_window.destroy()<\/p>\n<p>    root.deiconify()<\/p>\n<p>root = tk.Tk()<\/p>\n<p>root.title(&quot;\u4e3b\u7a97\u53e3&quot;)<\/p>\n<p>button = tk.Button(root, text=&quot;\u6253\u5f00\u7a97\u53e3 A&quot;, command=lambda: [root.withdraw(), open_window_a()])<\/p>\n<p>button.pack()<\/p>\n<p>root.mainloop()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u5b9a\u4e49\u4e86\u4e09\u4e2a\u51fd\u6570\uff1a<code>open_window_a<\/code>\uff0c<code>open_window_b<\/code>\u548c<code>open_main_window<\/code>\uff0c\u5206\u522b\u7528\u4e8e\u6253\u5f00\u7a97\u53e3A\u3001\u7a97\u53e3B\u548c\u56de\u5230\u4e3b\u7a97\u53e3\u3002\u5728\u6bcf\u4e2a\u51fd\u6570\u4e2d\uff0c\u6211\u4eec\u5148\u5173\u95ed\u5f53\u524d\u7a97\u53e3\uff0c\u7136\u540e\u6253\u5f00\u4e0b\u4e00\u4e2a\u7a97\u53e3\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001PyQt\u5b9e\u73b0\u7a97\u53e3\u8df3\u8f6c<\/h3>\n<\/p>\n<p><p>PyQt\u662f\u4e00\u4e2a\u529f\u80fd\u5f3a\u5927\u7684GUI\u5e93\uff0c\u9002\u7528\u4e8e\u5f00\u53d1\u590d\u6742\u7684\u684c\u9762\u5e94\u7528\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528PyQt\u521b\u5efa\u591a\u4e2a\u7a97\u53e3\uff0c\u5e76\u901a\u8fc7\u4fe1\u53f7\u548c\u69fd\u673a\u5236\u6765\u5b9e\u73b0\u7a97\u53e3\u4e4b\u95f4\u7684\u8df3\u8f6c\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u521b\u5efa\u4e3b\u7a97\u53e3\u548c\u5b50\u7a97\u53e3<\/h4>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u6211\u4eec\u521b\u5efa\u4e00\u4e2a\u4e3b\u7a97\u53e3\u548c\u4e00\u4e2a\u5b50\u7a97\u53e3\uff0c\u4e3b\u7a97\u53e3\u5305\u542b\u4e00\u4e2a\u6309\u94ae\uff0c\u5f53\u70b9\u51fb\u6309\u94ae\u65f6\uff0c\u6253\u5f00\u5b50\u7a97\u53e3\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import sys<\/p>\n<p>from PyQt5.QtWidgets import QApplication, QMainWindow, QPushButton, QWidget, QVBoxLayout<\/p>\n<p>class ChildWindow(QWidget):<\/p>\n<p>    def __init__(self):<\/p>\n<p>        super().__init__()<\/p>\n<p>        self.setWindowTitle(&quot;\u5b50\u7a97\u53e3&quot;)<\/p>\n<p>        layout = QVBoxLayout()<\/p>\n<p>        layout.addWidget(QPushButton(&quot;\u8fd9\u662f\u5b50\u7a97\u53e3&quot;))<\/p>\n<p>        self.setLayout(layout)<\/p>\n<p>class MainWindow(QMainWindow):<\/p>\n<p>    def __init__(self):<\/p>\n<p>        super().__init__()<\/p>\n<p>        self.setWindowTitle(&quot;\u4e3b\u7a97\u53e3&quot;)<\/p>\n<p>        button = QPushButton(&quot;\u6253\u5f00\u5b50\u7a97\u53e3&quot;)<\/p>\n<p>        button.clicked.connect(self.open_child_window)<\/p>\n<p>        self.setCentralWidget(button)<\/p>\n<p>    def open_child_window(self):<\/p>\n<p>        self.child_window = ChildWindow()<\/p>\n<p>        self.child_window.show()<\/p>\n<p>app = QApplication(sys.argv)<\/p>\n<p>main_window = MainWindow()<\/p>\n<p>main_window.show()<\/p>\n<p>sys.exit(app.exec_())<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u5b9a\u4e49\u4e86\u4e00\u4e2a<code>ChildWindow<\/code>\u7c7b\u548c\u4e00\u4e2a<code>MainWindow<\/code>\u7c7b\u3002<code>MainWindow<\/code>\u7c7b\u5305\u542b\u4e00\u4e2a\u6309\u94ae\uff0c\u5f53\u70b9\u51fb\u6309\u94ae\u65f6\uff0c\u521b\u5efa\u5e76\u663e\u793a\u4e00\u4e2a<code>ChildWindow<\/code>\u5b9e\u4f8b\u3002<\/p>\n<\/p>\n<p><h4>2\u3001\u5728\u591a\u4e2a\u7a97\u53e3\u4e4b\u95f4\u8df3\u8f6c<\/h4>\n<\/p>\n<p><p>\u4e3a\u4e86\u5728\u591a\u4e2a\u7a97\u53e3\u4e4b\u95f4\u8df3\u8f6c\uff0c\u6211\u4eec\u53ef\u4ee5\u5728\u6bcf\u4e2a\u7a97\u53e3\u4e2d\u653e\u7f6e\u6309\u94ae\uff0c\u901a\u8fc7\u4fe1\u53f7\u548c\u69fd\u673a\u5236\u6765\u5173\u95ed\u5f53\u524d\u7a97\u53e3\u5e76\u6253\u5f00\u53e6\u4e00\u4e2a\u7a97\u53e3\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import sys<\/p>\n<p>from PyQt5.QtWidgets import QApplication, QMainWindow, QPushButton, QWidget, QVBoxLayout<\/p>\n<p>class WindowA(QWidget):<\/p>\n<p>    def __init__(self, main_window):<\/p>\n<p>        super().__init__()<\/p>\n<p>        self.main_window = main_window<\/p>\n<p>        self.setWindowTitle(&quot;\u7a97\u53e3 A&quot;)<\/p>\n<p>        layout = QVBoxLayout()<\/p>\n<p>        button = QPushButton(&quot;\u6253\u5f00\u7a97\u53e3 B&quot;)<\/p>\n<p>        button.clicked.connect(self.open_window_b)<\/p>\n<p>        layout.addWidget(button)<\/p>\n<p>        self.setLayout(layout)<\/p>\n<p>    def open_window_b(self):<\/p>\n<p>        self.close()<\/p>\n<p>        self.window_b = WindowB(self.main_window)<\/p>\n<p>        self.window_b.show()<\/p>\n<p>class WindowB(QWidget):<\/p>\n<p>    def __init__(self, main_window):<\/p>\n<p>        super().__init__()<\/p>\n<p>        self.main_window = main_window<\/p>\n<p>        self.setWindowTitle(&quot;\u7a97\u53e3 B&quot;)<\/p>\n<p>        layout = QVBoxLayout()<\/p>\n<p>        button = QPushButton(&quot;\u56de\u5230\u4e3b\u7a97\u53e3&quot;)<\/p>\n<p>        button.clicked.connect(self.open_main_window)<\/p>\n<p>        layout.addWidget(button)<\/p>\n<p>        self.setLayout(layout)<\/p>\n<p>    def open_main_window(self):<\/p>\n<p>        self.close()<\/p>\n<p>        self.main_window.show()<\/p>\n<p>class MainWindow(QMainWindow):<\/p>\n<p>    def __init__(self):<\/p>\n<p>        super().__init__()<\/p>\n<p>        self.setWindowTitle(&quot;\u4e3b\u7a97\u53e3&quot;)<\/p>\n<p>        button = QPushButton(&quot;\u6253\u5f00\u7a97\u53e3 A&quot;)<\/p>\n<p>        button.clicked.connect(self.open_window_a)<\/p>\n<p>        self.setCentralWidget(button)<\/p>\n<p>    def open_window_a(self):<\/p>\n<p>        self.hide()<\/p>\n<p>        self.window_a = WindowA(self)<\/p>\n<p>        self.window_a.show()<\/p>\n<p>app = QApplication(sys.argv)<\/p>\n<p>main_window = MainWindow()<\/p>\n<p>main_window.show()<\/p>\n<p>sys.exit(app.exec_())<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u5b9a\u4e49\u4e86<code>WindowA<\/code>\u548c<code>WindowB<\/code>\u7c7b\uff0c\u5206\u522b\u8868\u793a\u7a97\u53e3A\u548c\u7a97\u53e3B\u3002\u5728\u6bcf\u4e2a\u7c7b\u4e2d\uff0c\u6211\u4eec\u5b9a\u4e49\u4e86\u4e00\u4e2a\u6309\u94ae\uff0c\u901a\u8fc7\u70b9\u51fb\u6309\u94ae\u6765\u5173\u95ed\u5f53\u524d\u7a97\u53e3\u5e76\u6253\u5f00\u4e0b\u4e00\u4e2a\u7a97\u53e3\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001Kivy\u5b9e\u73b0\u7a97\u53e3\u8df3\u8f6c<\/h3>\n<\/p>\n<p><p>Kivy\u662f\u4e00\u4e2a\u7528\u4e8e\u5f00\u53d1\u591a\u70b9\u89e6\u63a7\u5e94\u7528\u7a0b\u5e8f\u7684\u5f00\u6e90Python\u5e93\uff0c\u9002\u7528\u4e8e\u5f00\u53d1\u8de8\u5e73\u53f0\u5e94\u7528\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528Kivy\u521b\u5efa\u591a\u4e2a\u7a97\u53e3\uff0c\u5e76\u901a\u8fc7\u5c4f\u5e55\u7ba1\u7406\u5668\u6765\u5b9e\u73b0\u7a97\u53e3\u4e4b\u95f4\u7684\u8df3\u8f6c\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u521b\u5efa\u4e3b\u7a97\u53e3\u548c\u5b50\u7a97\u53e3<\/h4>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u6211\u4eec\u521b\u5efa\u4e00\u4e2a\u4e3b\u7a97\u53e3\u548c\u4e00\u4e2a\u5b50\u7a97\u53e3\uff0c\u4e3b\u7a97\u53e3\u5305\u542b\u4e00\u4e2a\u6309\u94ae\uff0c\u5f53\u70b9\u51fb\u6309\u94ae\u65f6\uff0c\u6253\u5f00\u5b50\u7a97\u53e3\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from kivy.app import App<\/p>\n<p>from kivy.uix.screenmanager import ScreenManager, Screen<\/p>\n<p>from kivy.uix.button import Button<\/p>\n<p>class MainWindow(Screen):<\/p>\n<p>    def __init__(self, kwargs):<\/p>\n<p>        super(MainWindow, self).__init__(kwargs)<\/p>\n<p>        button = Button(text=&quot;\u6253\u5f00\u5b50\u7a97\u53e3&quot;)<\/p>\n<p>        button.bind(on_release=self.open_child_window)<\/p>\n<p>        self.add_widget(button)<\/p>\n<p>    def open_child_window(self, instance):<\/p>\n<p>        self.manager.current = &#39;child&#39;<\/p>\n<p>class ChildWindow(Screen):<\/p>\n<p>    def __init__(self, kwargs):<\/p>\n<p>        super(ChildWindow, self).__init__(kwargs)<\/p>\n<p>        button = Button(text=&quot;\u8fd9\u662f\u5b50\u7a97\u53e3&quot;)<\/p>\n<p>        self.add_widget(button)<\/p>\n<p>class MyApp(App):<\/p>\n<p>    def build(self):<\/p>\n<p>        sm = ScreenManager()<\/p>\n<p>        sm.add_widget(MainWindow(name=&#39;main&#39;))<\/p>\n<p>        sm.add_widget(ChildWindow(name=&#39;child&#39;))<\/p>\n<p>        return sm<\/p>\n<p>if __name__ == &#39;__main__&#39;:<\/p>\n<p>    MyApp().run()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u5b9a\u4e49\u4e86<code>MainWindow<\/code>\u548c<code>ChildWindow<\/code>\u7c7b\uff0c\u5206\u522b\u8868\u793a\u4e3b\u7a97\u53e3\u548c\u5b50\u7a97\u53e3\u3002\u4f7f\u7528<code>ScreenManager<\/code>\u6765\u7ba1\u7406\u548c\u5207\u6362\u5c4f\u5e55\u3002<\/p>\n<\/p>\n<p><h4>2\u3001\u5728\u591a\u4e2a\u7a97\u53e3\u4e4b\u95f4\u8df3\u8f6c<\/h4>\n<\/p>\n<p><p>\u4e3a\u4e86\u5728\u591a\u4e2a\u7a97\u53e3\u4e4b\u95f4\u8df3\u8f6c\uff0c\u6211\u4eec\u53ef\u4ee5\u5728\u6bcf\u4e2a\u7a97\u53e3\u4e2d\u653e\u7f6e\u6309\u94ae\uff0c\u901a\u8fc7\u5c4f\u5e55\u7ba1\u7406\u5668\u6765\u5207\u6362\u5c4f\u5e55\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from kivy.app import App<\/p>\n<p>from kivy.uix.screenmanager import ScreenManager, Screen<\/p>\n<p>from kivy.uix.button import Button<\/p>\n<p>class WindowA(Screen):<\/p>\n<p>    def __init__(self, kwargs):<\/p>\n<p>        super(WindowA, self).__init__(kwargs)<\/p>\n<p>        button = Button(text=&quot;\u6253\u5f00\u7a97\u53e3 B&quot;)<\/p>\n<p>        button.bind(on_release=self.open_window_b)<\/p>\n<p>        self.add_widget(button)<\/p>\n<p>    def open_window_b(self, instance):<\/p>\n<p>        self.manager.current = &#39;window_b&#39;<\/p>\n<p>class WindowB(Screen):<\/p>\n<p>    def __init__(self, kwargs):<\/p>\n<p>        super(WindowB, self).__init__(kwargs)<\/p>\n<p>        button = Button(text=&quot;\u56de\u5230\u4e3b\u7a97\u53e3&quot;)<\/p>\n<p>        button.bind(on_release=self.open_main_window)<\/p>\n<p>        self.add_widget(button)<\/p>\n<p>    def open_main_window(self, instance):<\/p>\n<p>        self.manager.current = &#39;main&#39;<\/p>\n<p>class MainWindow(Screen):<\/p>\n<p>    def __init__(self, kwargs):<\/p>\n<p>        super(MainWindow, self).__init__(kwargs)<\/p>\n<p>        button = Button(text=&quot;\u6253\u5f00\u7a97\u53e3 A&quot;)<\/p>\n<p>        button.bind(on_release=self.open_window_a)<\/p>\n<p>        self.add_widget(button)<\/p>\n<p>    def open_window_a(self, instance):<\/p>\n<p>        self.manager.current = &#39;window_a&#39;<\/p>\n<p>class MyApp(App):<\/p>\n<p>    def build(self):<\/p>\n<p>        sm = ScreenManager()<\/p>\n<p>        sm.add_widget(MainWindow(name=&#39;main&#39;))<\/p>\n<p>        sm.add_widget(WindowA(name=&#39;window_a&#39;))<\/p>\n<p>        sm.add_widget(WindowB(name=&#39;window_b&#39;))<\/p>\n<p>        return sm<\/p>\n<p>if __name__ == &#39;__main__&#39;:<\/p>\n<p>    MyApp().run()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u5b9a\u4e49\u4e86<code>WindowA<\/code>\u548c<code>WindowB<\/code>\u7c7b\uff0c\u5206\u522b\u8868\u793a\u7a97\u53e3A\u548c\u7a97\u53e3B\u3002\u4f7f\u7528<code>ScreenManager<\/code>\u6765\u7ba1\u7406\u548c\u5207\u6362\u5c4f\u5e55\uff0c\u901a\u8fc7\u6309\u94ae\u7ed1\u5b9a\u7684\u4e8b\u4ef6\u6765\u5207\u6362\u5c4f\u5e55\u3002<\/p>\n<\/p>\n<p><h3>\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u5b9e\u73b0\u7a97\u53e3\u4e4b\u95f4\u7684\u8df3\u8f6c\u53ef\u4ee5\u4f7f\u7528\u4e0d\u540c\u7684GUI\u5e93\uff0c\u5982Tkinter\u3001PyQt\u548cKivy\u3002\u6bcf\u4e2a\u5e93\u90fd\u6709\u5176\u72ec\u7279\u7684\u7279\u70b9\u548c\u9002\u7528\u573a\u666f\u3002\u901a\u8fc7\u4e0a\u8ff0\u793a\u4f8b\u4ee3\u7801\uff0c\u6211\u4eec\u53ef\u4ee5\u638c\u63e1\u5982\u4f55\u4f7f\u7528\u8fd9\u4e9b\u5e93\u6765\u521b\u5efa\u591a\u4e2a\u7a97\u53e3\uff0c\u5e76\u5b9e\u73b0\u7a97\u53e3\u4e4b\u95f4\u7684\u8df3\u8f6c\u3002\u6839\u636e\u5177\u4f53\u9700\u6c42\u548c\u5e94\u7528\u573a\u666f\uff0c\u9009\u62e9\u5408\u9002\u7684\u5e93\u6765\u5f00\u53d1\u4f60\u7684\u684c\u9762\u5e94\u7528\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5728Python\u4e2d\uff0c\u5982\u4f55\u521b\u5efa\u591a\u4e2a\u7a97\u53e3\u5e76\u5b9e\u73b0\u7a97\u53e3\u95f4\u7684\u8df3\u8f6c\uff1f<\/strong><br \/>\u53ef\u4ee5\u4f7f\u7528Tkinter\u5e93\u6765\u521b\u5efa\u591a\u4e2a\u7a97\u53e3\u3002\u5728Tkinter\u4e2d\uff0c\u6bcf\u4e2a\u7a97\u53e3\u90fd\u662f\u4e00\u4e2a\u72ec\u7acb\u7684Toplevel\u5bf9\u8c61\u3002\u60a8\u53ef\u4ee5\u901a\u8fc7\u8c03\u7528\u4e0d\u540c\u7a97\u53e3\u7684<code>withdraw()<\/code>\u548c<code>deiconify()<\/code>\u65b9\u6cd5\u6765\u5b9e\u73b0\u7a97\u53e3\u95f4\u7684\u8df3\u8f6c\u3002\u6bd4\u5982\uff0c\u60a8\u53ef\u4ee5\u5728\u4e00\u4e2a\u7a97\u53e3\u4e2d\u6309\u4e0b\u6309\u94ae\u540e\u9690\u85cf\u5f53\u524d\u7a97\u53e3\uff0c\u5e76\u663e\u793a\u53e6\u4e00\u4e2a\u7a97\u53e3\u3002<\/p>\n<p><strong>\u5728\u4f7f\u7528Tkinter\u65f6\uff0c\u6709\u54ea\u4e9b\u6280\u5de7\u53ef\u4ee5\u63d0\u9ad8\u7a97\u53e3\u95f4\u8df3\u8f6c\u7684\u7528\u6237\u4f53\u9a8c\uff1f<\/strong><br \/>\u5728\u7a97\u53e3\u95f4\u8df3\u8f6c\u65f6\uff0c\u53ef\u4ee5\u6dfb\u52a0\u52a8\u753b\u6548\u679c\u6216\u4f7f\u7528\u8fc7\u6e21\u6548\u679c\u6765\u63d0\u5347\u7528\u6237\u4f53\u9a8c\u3002\u901a\u8fc7\u8bbe\u7f6e\u7a97\u53e3\u7684\u900f\u660e\u5ea6\u6216\u4f7f\u7528<code>geometry()<\/code>\u65b9\u6cd5\u6539\u53d8\u7a97\u53e3\u5c3a\u5bf8\u53ef\u4ee5\u4f7f\u7528\u6237\u611f\u53d7\u5230\u66f4\u52a0\u6d41\u7545\u7684\u754c\u9762\u5207\u6362\u3002\u6b64\u5916\uff0c\u5408\u7406\u5b89\u6392\u6309\u94ae\u7684\u4f4d\u7f6e\u548c\u529f\u80fd\uff0c\u4f7f\u7528\u6237\u80fd\u591f\u5feb\u901f\u627e\u5230\u6240\u9700\u7684\u64cd\u4f5c\uff0c\u4e5f\u975e\u5e38\u91cd\u8981\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728\u4e0d\u540c\u7684\u7a97\u53e3\u4e4b\u95f4\u4f20\u9012\u6570\u636e\uff1f<\/strong><br \/>\u5728\u591a\u4e2a\u7a97\u53e3\u95f4\u4f20\u9012\u6570\u636e\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u5f0f\u5b9e\u73b0\u3002\u53ef\u4ee5\u5728\u521b\u5efa\u65b0\u7a97\u53e3\u65f6\uff0c\u5c06\u6570\u636e\u4f5c\u4e3a\u53c2\u6570\u4f20\u9012\u7ed9\u7a97\u53e3\u7684\u521d\u59cb\u5316\u51fd\u6570\uff0c\u6216\u8005\u4f7f\u7528\u5168\u5c40\u53d8\u91cf\u4fdd\u5b58\u6570\u636e\u3002\u5728Tkinter\u4e2d\uff0c\u4e5f\u53ef\u4ee5\u4f7f\u7528<code>StringVar<\/code>\u7b49\u53d8\u91cf\u7c7b\u6765\u5b9e\u73b0\u6570\u636e\u7ed1\u5b9a\uff0c\u786e\u4fdd\u6570\u636e\u5728\u7a97\u53e3\u95f4\u7684\u540c\u6b65\u66f4\u65b0\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python\u7a97\u53e3\u4e4b\u95f4\u7684\u8df3\u8f6c\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528GUI\u5e93\u5982Tkinter\u3001PyQt\u3001Kivy\u6765\u5b9e\u73b0\uff0c\u901a\u8fc7\u5728\u4e0d\u540c\u7a97\u53e3\u4e4b\u95f4\u5207 [&hellip;]","protected":false},"author":3,"featured_media":1033036,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1033031"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=1033031"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1033031\/revisions"}],"predecessor-version":[{"id":1033038,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1033031\/revisions\/1033038"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1033036"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1033031"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1033031"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1033031"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}