{"id":1018165,"date":"2024-12-27T12:38:43","date_gmt":"2024-12-27T04:38:43","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1018165.html"},"modified":"2024-12-27T12:38:45","modified_gmt":"2024-12-27T04:38:45","slug":"python%e5%a6%82%e4%bd%95%e5%bc%80%e5%8f%91windows%e7%95%8c%e9%9d%a2","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1018165.html","title":{"rendered":"python\u5982\u4f55\u5f00\u53d1windows\u754c\u9762"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25160904\/335b2f62-0d9c-47e4-bf43-e2986a6473a1.webp\" alt=\"python\u5982\u4f55\u5f00\u53d1windows\u754c\u9762\" \/><\/p>\n<p><p> \u5728Python\u4e2d\u5f00\u53d1Windows\u754c\u9762\u7684\u65b9\u6cd5\u6709\u591a\u79cd\uff0c<strong>\u5e38\u89c1\u7684\u65b9\u6cd5\u6709\u4f7f\u7528Tkinter\u3001PyQt\u3001Kivy\u3001wxPython\u7b49\u5e93<\/strong>\u3002\u5176\u4e2d\uff0c<strong>Tkinter\u662fPython\u7684\u6807\u51c6GUI\u5e93\uff0c\u7b80\u5355\u6613\u7528<\/strong>\uff0c<strong>PyQt\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u529f\u80fd\u548c\u4e30\u5bcc\u7684\u7ec4\u4ef6<\/strong>\uff0c\u9002\u5408\u9700\u8981\u590d\u6742\u754c\u9762\u7684\u5e94\u7528\u3002<strong>Kivy\u9002\u5408\u8de8\u5e73\u53f0\u5f00\u53d1<\/strong>\uff0c\u5e76\u652f\u6301\u591a\u70b9\u89e6\u63a7\u529f\u80fd\uff0c<strong>wxPython\u5219\u63d0\u4f9b\u4e86\u539f\u751f\u7684\u754c\u9762\u98ce\u683c<\/strong>\u3002\u4e0b\u9762\u6211\u5c06\u8be6\u7ec6\u4ecb\u7ecdTkinter\u7684\u4f7f\u7528\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001Tkinter\u57fa\u7840\u4ecb\u7ecd<\/h3>\n<\/p>\n<p><p>Tkinter\u662fPython\u7684\u6807\u51c6GUI\u5e93\uff0c\u5b83\u7b80\u5355\u6613\u7528\uff0c\u9002\u5408\u5c0f\u578b\u6216\u4e2d\u7b49\u89c4\u6a21\u7684\u5e94\u7528\u5f00\u53d1\u3002Tkinter\u63d0\u4f9b\u4e86\u4e00\u7ec4\u7b80\u5355\u7684\u90e8\u4ef6\uff08\u5982\u6309\u94ae\u3001\u6807\u7b7e\u3001\u6587\u672c\u6846\uff09\u6765\u6784\u5efa\u7528\u6237\u754c\u9762\u3002\u4f7f\u7528Tkinter\u7684\u57fa\u672c\u6b65\u9aa4\u5305\u62ec\u521b\u5efa\u4e3b\u7a97\u53e3\u3001\u6dfb\u52a0\u90e8\u4ef6\u3001\u8bbe\u7f6e\u5e03\u5c40\u548c\u4e8b\u4ef6\u5904\u7406\u3002<\/p>\n<\/p>\n<p><p>Tkinter\u7684\u4e3b\u8981\u4f18\u52bf\u5728\u4e8e\u5176\u7b80\u5355\u6027\u548c\u6613\u7528\u6027\u3002\u5b83\u662fPython\u7684\u6807\u51c6\u5e93\uff0c\u610f\u5473\u7740\u4e0d\u9700\u8981\u989d\u5916\u5b89\u88c5\u5373\u53ef\u4f7f\u7528\u3002\u6b64\u5916\uff0cTkinter\u7684\u90e8\u4ef6\u7b80\u5355\u76f4\u89c2\uff0c\u9002\u5408\u5feb\u901f\u6784\u5efa\u539f\u578b\u6216\u7b80\u5355\u7684\u7528\u6237\u754c\u9762\u3002\u5373\u4fbf\u662f\u521d\u5b66\u8005\uff0c\u4e5f\u80fd\u5728\u77ed\u65f6\u95f4\u5185\u638c\u63e1\u5176\u57fa\u672c\u7528\u6cd5\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001Tkinter\u7684\u57fa\u672c\u7ec4\u4ef6<\/h3>\n<\/p>\n<p><p>Tkinter\u63d0\u4f9b\u4e86\u591a\u79cd\u57fa\u672c\u7ec4\u4ef6\uff0c\u5982\u6807\u7b7e\u3001\u6309\u94ae\u3001\u6587\u672c\u6846\u3001\u590d\u9009\u6846\u3001\u5355\u9009\u6309\u94ae\u3001\u5217\u8868\u6846\u7b49\u3002\u6bcf\u79cd\u7ec4\u4ef6\u90fd\u6709\u5176\u7279\u5b9a\u7684\u7528\u9014\u548c\u5c5e\u6027\uff0c\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e\u4e0d\u540c\u7684\u5c5e\u6027\u6765\u81ea\u5b9a\u4e49\u7ec4\u4ef6\u7684\u5916\u89c2\u548c\u884c\u4e3a\u3002<\/p>\n<\/p>\n<p><h4>1. \u6807\u7b7e\uff08Label\uff09<\/h4>\n<\/p>\n<p><p>\u6807\u7b7e\u7528\u4e8e\u663e\u793a\u6587\u672c\u6216\u56fe\u50cf\uff0c\u662f\u6700\u57fa\u672c\u7684\u7ec4\u4ef6\u4e4b\u4e00\u3002\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e\u6587\u672c\u3001\u5b57\u4f53\u3001\u989c\u8272\u7b49\u5c5e\u6027\u6765\u6539\u53d8\u6807\u7b7e\u7684\u5916\u89c2\u3002\u521b\u5efa\u6807\u7b7e\u975e\u5e38\u7b80\u5355\uff0c\u53ea\u9700\u5b9e\u4f8b\u5316<code>Label<\/code>\u7c7b\u5e76\u6307\u5b9a\u76f8\u5e94\u7684\u5c5e\u6027\u5373\u53ef\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from tkinter import Tk, Label<\/p>\n<p>root = Tk()<\/p>\n<p>label = Label(root, text=&quot;Hello, World!&quot;)<\/p>\n<p>label.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><h4>2. \u6309\u94ae\uff08Button\uff09<\/h4>\n<\/p>\n<p><p>\u6309\u94ae\u662f\u7528\u4e8e\u89e6\u53d1\u4e8b\u4ef6\u7684\u7ec4\u4ef6\u3002\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e\u547d\u4ee4\u5c5e\u6027\u6765\u6307\u5b9a\u6309\u94ae\u88ab\u70b9\u51fb\u65f6\u8c03\u7528\u7684\u51fd\u6570\u3002\u6309\u94ae\u7684\u5916\u89c2\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e\u6587\u672c\u3001\u989c\u8272\u7b49\u5c5e\u6027\u6765\u8c03\u6574\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from tkinter import Tk, Button<\/p>\n<p>def on_click():<\/p>\n<p>    print(&quot;Button clicked!&quot;)<\/p>\n<p>root = Tk()<\/p>\n<p>button = Button(root, text=&quot;Click Me&quot;, command=on_click)<\/p>\n<p>button.pack()<\/p>\n<p>root.mainloop()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e09\u3001Tkinter\u5e03\u5c40\u7ba1\u7406<\/h3>\n<\/p>\n<p><p>Tkinter\u63d0\u4f9b\u4e86\u4e09\u79cd\u5e03\u5c40\u7ba1\u7406\u5668\uff1apack\u3001grid\u548cplace\u3002\u6bcf\u79cd\u5e03\u5c40\u7ba1\u7406\u5668\u90fd\u6709\u5176\u7279\u5b9a\u7684\u7528\u9014\u548c\u4f18\u52bf\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u6839\u636e\u5177\u4f53\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u5e03\u5c40\u7ba1\u7406\u5668\u3002<\/p>\n<\/p>\n<p><h4>1. Pack\u5e03\u5c40<\/h4>\n<\/p>\n<p><p>Pack\u5e03\u5c40\u662f\u6700\u7b80\u5355\u7684\u5e03\u5c40\u7ba1\u7406\u5668\uff0c\u5b83\u6309\u987a\u5e8f\u6392\u5217\u7ec4\u4ef6\u3002\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e\u7ec4\u4ef6\u7684\u586b\u5145\u65b9\u5f0f\uff08\u6c34\u5e73\u6216\u5782\u76f4\uff09\u6765\u8c03\u6574\u7ec4\u4ef6\u7684\u6392\u5217\u65b9\u5411\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from tkinter import Tk, Button<\/p>\n<p>root = Tk()<\/p>\n<p>button1 = Button(root, text=&quot;Button 1&quot;)<\/p>\n<p>button1.pack(side=&quot;left&quot;)<\/p>\n<p>button2 = Button(root, text=&quot;Button 2&quot;)<\/p>\n<p>button2.pack(side=&quot;right&quot;)<\/p>\n<p>root.mainloop()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2. Grid\u5e03\u5c40<\/h4>\n<\/p>\n<p><p>Grid\u5e03\u5c40\u5141\u8bb8\u5f00\u53d1\u8005\u5c06\u7ec4\u4ef6\u6392\u5217\u5728\u7f51\u683c\u4e2d\u3002\u53ef\u4ee5\u901a\u8fc7\u6307\u5b9a\u884c\u548c\u5217\u7684\u4f4d\u7f6e\u6765\u7cbe\u786e\u63a7\u5236\u7ec4\u4ef6\u7684\u4f4d\u7f6e\u3002Grid\u5e03\u5c40\u9002\u5408\u9700\u8981\u7cbe\u786e\u63a7\u5236\u7ec4\u4ef6\u4f4d\u7f6e\u7684\u573a\u666f\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from tkinter import Tk, Button<\/p>\n<p>root = Tk()<\/p>\n<p>button1 = Button(root, text=&quot;Button 1&quot;)<\/p>\n<p>button1.grid(row=0, column=0)<\/p>\n<p>button2 = Button(root, text=&quot;Button 2&quot;)<\/p>\n<p>button2.grid(row=0, column=1)<\/p>\n<p>root.mainloop()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u56db\u3001\u4e8b\u4ef6\u5904\u7406<\/h3>\n<\/p>\n<p><p>\u4e8b\u4ef6\u5904\u7406\u662fGUI\u5e94\u7528\u7684\u91cd\u8981\u90e8\u5206\uff0c\u5b83\u51b3\u5b9a\u4e86\u5e94\u7528\u5982\u4f55\u54cd\u5e94\u7528\u6237\u7684\u64cd\u4f5c\u3002Tkinter\u901a\u8fc7\u7ed1\u5b9a\u4e8b\u4ef6\u5904\u7406\u51fd\u6570\u6765\u5b9e\u73b0\u4e8b\u4ef6\u5904\u7406\u3002<\/p>\n<\/p>\n<p><h4>1. \u7ed1\u5b9a\u4e8b\u4ef6<\/h4>\n<\/p>\n<p><p>\u53ef\u4ee5\u901a\u8fc7<code>bind<\/code>\u65b9\u6cd5\u5c06\u4e8b\u4ef6\u4e0e\u5904\u7406\u51fd\u6570\u7ed1\u5b9a\u3002\u4e8b\u4ef6\u53ef\u4ee5\u662f\u9f20\u6807\u70b9\u51fb\u3001\u952e\u76d8\u6309\u952e\u7b49\u3002\u5904\u7406\u51fd\u6570\u53ef\u4ee5\u63a5\u6536\u4e8b\u4ef6\u5bf9\u8c61\u4f5c\u4e3a\u53c2\u6570\uff0c\u4ee5\u83b7\u53d6\u4e8b\u4ef6\u7684\u8be6\u7ec6\u4fe1\u606f\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from tkinter import Tk, Button<\/p>\n<p>def on_click(event):<\/p>\n<p>    print(f&quot;Button clicked at {event.x}, {event.y}&quot;)<\/p>\n<p>root = Tk()<\/p>\n<p>button = Button(root, text=&quot;Click Me&quot;)<\/p>\n<p>button.bind(&quot;&lt;Button-1&gt;&quot;, on_click)<\/p>\n<p>button.pack()<\/p>\n<p>root.mainloop()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2. \u4f7f\u7528\u547d\u4ee4\u5c5e\u6027<\/h4>\n<\/p>\n<p><p>\u5bf9\u4e8e\u6309\u94ae\u7b49\u7ec4\u4ef6\uff0c\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e\u547d\u4ee4\u5c5e\u6027\u6765\u6307\u5b9a\u4e8b\u4ef6\u5904\u7406\u51fd\u6570\u3002\u8fd9\u79cd\u65b9\u5f0f\u9002\u5408\u7b80\u5355\u7684\u4e8b\u4ef6\u5904\u7406\u573a\u666f\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from tkinter import Tk, Button<\/p>\n<p>def on_click():<\/p>\n<p>    print(&quot;Button clicked!&quot;)<\/p>\n<p>root = Tk()<\/p>\n<p>button = Button(root, text=&quot;Click Me&quot;, command=on_click)<\/p>\n<p>button.pack()<\/p>\n<p>root.mainloop()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e94\u3001PyQt\u57fa\u7840\u4ecb\u7ecd<\/h3>\n<\/p>\n<p><p>PyQt\u662fPython\u7684\u53e6\u4e00\u79cd\u6d41\u884c\u7684GUI\u5e93\uff0c\u57fa\u4e8eQt\u6846\u67b6\uff0c\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u7ec4\u4ef6\u548c\u5f3a\u5927\u7684\u529f\u80fd\u3002PyQt\u9002\u5408\u9700\u8981\u590d\u6742\u754c\u9762\u7684\u5e94\u7528\u5f00\u53d1\u3002\u4e0eTkinter\u76f8\u6bd4\uff0cPyQt\u63d0\u4f9b\u4e86\u66f4\u591a\u7684\u7ec4\u4ef6\u548c\u529f\u80fd\uff0c\u5982\u6a21\u578b-\u89c6\u56fe-\u63a7\u5236\u5668\uff08MVC\uff09\u67b6\u6784\u3001\u4fe1\u53f7\u4e0e\u69fd\u673a\u5236\u7b49\u3002<\/p>\n<\/p>\n<p><p>PyQt\u7684\u4e3b\u8981\u4f18\u52bf\u5728\u4e8e\u5176\u5f3a\u5927\u7684\u529f\u80fd\u548c\u4e30\u5bcc\u7684\u7ec4\u4ef6\u3002\u5b83\u63d0\u4f9b\u4e86\u4e0eQt\u6846\u67b6\u4e00\u81f4\u7684API\uff0c\u4f7f\u5f97\u5f00\u53d1\u8005\u53ef\u4ee5\u65b9\u4fbf\u5730\u5229\u7528Qt\u7684\u5f3a\u5927\u529f\u80fd\u3002\u6b64\u5916\uff0cPyQt\u8fd8\u652f\u6301\u8de8\u5e73\u53f0\u5f00\u53d1\uff0c\u9002\u5408\u9700\u8981\u5728\u591a\u4e2a\u5e73\u53f0\u4e0a\u8fd0\u884c\u7684\u5e94\u7528\u3002<\/p>\n<\/p>\n<p><h3>\u516d\u3001PyQt\u7684\u57fa\u672c\u7ec4\u4ef6<\/h3>\n<\/p>\n<p><p>PyQt\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u7ec4\u4ef6\uff0c\u5982\u6807\u7b7e\u3001\u6309\u94ae\u3001\u6587\u672c\u6846\u3001\u590d\u9009\u6846\u3001\u5355\u9009\u6309\u94ae\u3001\u5217\u8868\u6846\u7b49\u3002\u6bcf\u79cd\u7ec4\u4ef6\u90fd\u6709\u5176\u7279\u5b9a\u7684\u7528\u9014\u548c\u5c5e\u6027\uff0c\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e\u4e0d\u540c\u7684\u5c5e\u6027\u6765\u81ea\u5b9a\u4e49\u7ec4\u4ef6\u7684\u5916\u89c2\u548c\u884c\u4e3a\u3002<\/p>\n<\/p>\n<p><h4>1. \u6807\u7b7e\uff08QLabel\uff09<\/h4>\n<\/p>\n<p><p>\u6807\u7b7e\u7528\u4e8e\u663e\u793a\u6587\u672c\u6216\u56fe\u50cf\uff0c\u662f\u6700\u57fa\u672c\u7684\u7ec4\u4ef6\u4e4b\u4e00\u3002\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e\u6587\u672c\u3001\u5b57\u4f53\u3001\u989c\u8272\u7b49\u5c5e\u6027\u6765\u6539\u53d8\u6807\u7b7e\u7684\u5916\u89c2\u3002\u521b\u5efa\u6807\u7b7e\u975e\u5e38\u7b80\u5355\uff0c\u53ea\u9700\u5b9e\u4f8b\u5316<code>QLabel<\/code>\u7c7b\u5e76\u6307\u5b9a\u76f8\u5e94\u7684\u5c5e\u6027\u5373\u53ef\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from PyQt5.QtWidgets import QApplication, QLabel<\/p>\n<p>app = QApplication([])<\/p>\n<p>label = QLabel(&quot;Hello, World!&quot;)<\/p>\n<p>label.show()<\/p>\n<p>app.exec_()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2. \u6309\u94ae\uff08QPushButton\uff09<\/h4>\n<\/p>\n<p><p>\u6309\u94ae\u662f\u7528\u4e8e\u89e6\u53d1\u4e8b\u4ef6\u7684\u7ec4\u4ef6\u3002\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e\u70b9\u51fb\u4fe1\u53f7\u6765\u6307\u5b9a\u6309\u94ae\u88ab\u70b9\u51fb\u65f6\u8c03\u7528\u7684\u51fd\u6570\u3002\u6309\u94ae\u7684\u5916\u89c2\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e\u6587\u672c\u3001\u989c\u8272\u7b49\u5c5e\u6027\u6765\u8c03\u6574\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from PyQt5.QtWidgets import QApplication, QPushButton<\/p>\n<p>def on_click():<\/p>\n<p>    print(&quot;Button clicked!&quot;)<\/p>\n<p>app = QApplication([])<\/p>\n<p>button = QPushButton(&quot;Click Me&quot;)<\/p>\n<p>button.clicked.connect(on_click)<\/p>\n<p>button.show()<\/p>\n<p>app.exec_()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e03\u3001PyQt\u5e03\u5c40\u7ba1\u7406<\/h3>\n<\/p>\n<p><p>PyQt\u63d0\u4f9b\u4e86\u591a\u79cd\u5e03\u5c40\u7ba1\u7406\u5668\uff0c\u5982\u6c34\u5e73\u5e03\u5c40\u3001\u5782\u76f4\u5e03\u5c40\u3001\u7f51\u683c\u5e03\u5c40\u7b49\u3002\u6bcf\u79cd\u5e03\u5c40\u7ba1\u7406\u5668\u90fd\u6709\u5176\u7279\u5b9a\u7684\u7528\u9014\u548c\u4f18\u52bf\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u6839\u636e\u5177\u4f53\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u5e03\u5c40\u7ba1\u7406\u5668\u3002<\/p>\n<\/p>\n<p><h4>1. \u6c34\u5e73\u5e03\u5c40\uff08QHBoxLayout\uff09<\/h4>\n<\/p>\n<p><p>\u6c34\u5e73\u5e03\u5c40\u7528\u4e8e\u5c06\u7ec4\u4ef6\u6c34\u5e73\u6392\u5217\u3002\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e\u7ec4\u4ef6\u7684\u586b\u5145\u65b9\u5f0f\u6765\u8c03\u6574\u7ec4\u4ef6\u7684\u6392\u5217\u65b9\u5411\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QHBoxLayout<\/p>\n<p>app = QApplication([])<\/p>\n<p>window = QWidget()<\/p>\n<p>layout = QHBoxLayout()<\/p>\n<p>button1 = QPushButton(&quot;Button 1&quot;)<\/p>\n<p>layout.addWidget(button1)<\/p>\n<p>button2 = QPushButton(&quot;Button 2&quot;)<\/p>\n<p>layout.addWidget(button2)<\/p>\n<p>window.setLayout(layout)<\/p>\n<p>window.show()<\/p>\n<p>app.exec_()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2. \u7f51\u683c\u5e03\u5c40\uff08QGridLayout\uff09<\/h4>\n<\/p>\n<p><p>\u7f51\u683c\u5e03\u5c40\u5141\u8bb8\u5f00\u53d1\u8005\u5c06\u7ec4\u4ef6\u6392\u5217\u5728\u7f51\u683c\u4e2d\u3002\u53ef\u4ee5\u901a\u8fc7\u6307\u5b9a\u884c\u548c\u5217\u7684\u4f4d\u7f6e\u6765\u7cbe\u786e\u63a7\u5236\u7ec4\u4ef6\u7684\u4f4d\u7f6e\u3002\u7f51\u683c\u5e03\u5c40\u9002\u5408\u9700\u8981\u7cbe\u786e\u63a7\u5236\u7ec4\u4ef6\u4f4d\u7f6e\u7684\u573a\u666f\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QGridLayout<\/p>\n<p>app = QApplication([])<\/p>\n<p>window = QWidget()<\/p>\n<p>layout = QGridLayout()<\/p>\n<p>button1 = QPushButton(&quot;Button 1&quot;)<\/p>\n<p>layout.addWidget(button1, 0, 0)<\/p>\n<p>button2 = QPushButton(&quot;Button 2&quot;)<\/p>\n<p>layout.addWidget(button2, 0, 1)<\/p>\n<p>window.setLayout(layout)<\/p>\n<p>window.show()<\/p>\n<p>app.exec_()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u516b\u3001\u4e8b\u4ef6\u5904\u7406<\/h3>\n<\/p>\n<p><p>\u4e8b\u4ef6\u5904\u7406\u662fGUI\u5e94\u7528\u7684\u91cd\u8981\u90e8\u5206\uff0c\u5b83\u51b3\u5b9a\u4e86\u5e94\u7528\u5982\u4f55\u54cd\u5e94\u7528\u6237\u7684\u64cd\u4f5c\u3002PyQt\u901a\u8fc7\u4fe1\u53f7\u4e0e\u69fd\u673a\u5236\u6765\u5b9e\u73b0\u4e8b\u4ef6\u5904\u7406\u3002<\/p>\n<\/p>\n<p><h4>1. \u4fe1\u53f7\u4e0e\u69fd\u673a\u5236<\/h4>\n<\/p>\n<p><p>\u4fe1\u53f7\u4e0e\u69fd\u673a\u5236\u662fPyQt\u7684\u6838\u5fc3\u529f\u80fd\u4e4b\u4e00\u3002\u4fe1\u53f7\u7528\u4e8e\u8868\u793a\u4e8b\u4ef6\uff0c\u69fd\u662f\u4e8b\u4ef6\u5904\u7406\u51fd\u6570\u3002\u53ef\u4ee5\u901a\u8fc7\u8fde\u63a5\u4fe1\u53f7\u4e0e\u69fd\u6765\u5904\u7406\u4e8b\u4ef6\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from PyQt5.QtWidgets import QApplication, QPushButton<\/p>\n<p>def on_click():<\/p>\n<p>    print(&quot;Button clicked!&quot;)<\/p>\n<p>app = QApplication([])<\/p>\n<p>button = QPushButton(&quot;Click Me&quot;)<\/p>\n<p>button.clicked.connect(on_click)<\/p>\n<p>button.show()<\/p>\n<p>app.exec_()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2. \u81ea\u5b9a\u4e49\u4fe1\u53f7\u4e0e\u69fd<\/h4>\n<\/p>\n<p><p>\u9664\u4e86\u4f7f\u7528PyQt\u63d0\u4f9b\u7684\u4fe1\u53f7\u4e0e\u69fd\u5916\uff0c\u8fd8\u53ef\u4ee5\u81ea\u5b9a\u4e49\u4fe1\u53f7\u4e0e\u69fd\u3002\u81ea\u5b9a\u4e49\u4fe1\u53f7\u4e0e\u69fd\u9002\u5408\u9700\u8981\u81ea\u5b9a\u4e49\u4e8b\u4ef6\u5904\u7406\u7684\u573a\u666f\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from PyQt5.QtCore import QObject, pyqtSignal<\/p>\n<p>class Communicate(QObject):<\/p>\n<p>    customSignal = pyqtSignal()<\/p>\n<p>def on_custom_signal():<\/p>\n<p>    print(&quot;Custom signal emitted!&quot;)<\/p>\n<p>app = QApplication([])<\/p>\n<p>com = Communicate()<\/p>\n<p>com.customSignal.connect(on_custom_signal)<\/p>\n<p>com.customSignal.emit()<\/p>\n<p>app.exec_()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e5d\u3001Kivy\u57fa\u7840\u4ecb\u7ecd<\/h3>\n<\/p>\n<p><p>Kivy\u662f\u4e00\u4e2a\u5f00\u6e90\u7684Python\u5e93\uff0c\u7528\u4e8e\u5feb\u901f\u5f00\u53d1\u591a\u70b9\u89e6\u63a7\u5e94\u7528\u7a0b\u5e8f\u3002\u5b83\u9002\u5408\u8de8\u5e73\u53f0\u5f00\u53d1\uff0c\u652f\u6301Windows\u3001macOS\u3001Linux\u3001Android\u548ciOS\u3002Kivy\u7684\u4e3b\u8981\u4f18\u52bf\u5728\u4e8e\u5176\u7075\u6d3b\u6027\u548c\u8de8\u5e73\u53f0\u80fd\u529b\u3002<\/p>\n<\/p>\n<p><p>Kivy\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u7ec4\u4ef6\u548c\u529f\u80fd\uff0c\u5982\u591a\u70b9\u89e6\u63a7\u652f\u6301\u3001\u52a8\u753b\u3001\u56fe\u5f62\u7ed8\u5236\u7b49\u3002\u5b83\u7684\u67b6\u6784\u57fa\u4e8e\u4e8b\u4ef6\u9a71\u52a8\u7684\u6a21\u578b\uff0c\u4f7f\u5f97\u5f00\u53d1\u8005\u53ef\u4ee5\u65b9\u4fbf\u5730\u5904\u7406\u7528\u6237\u4ea4\u4e92\u3002<\/p>\n<\/p>\n<p><h3>\u5341\u3001Kivy\u7684\u57fa\u672c\u7ec4\u4ef6<\/h3>\n<\/p>\n<p><p>Kivy\u63d0\u4f9b\u4e86\u591a\u79cd\u57fa\u672c\u7ec4\u4ef6\uff0c\u5982\u6309\u94ae\u3001\u6807\u7b7e\u3001\u6587\u672c\u8f93\u5165\u6846\u3001\u6ed1\u5757\u7b49\u3002\u6bcf\u79cd\u7ec4\u4ef6\u90fd\u6709\u5176\u7279\u5b9a\u7684\u7528\u9014\u548c\u5c5e\u6027\uff0c\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e\u4e0d\u540c\u7684\u5c5e\u6027\u6765\u81ea\u5b9a\u4e49\u7ec4\u4ef6\u7684\u5916\u89c2\u548c\u884c\u4e3a\u3002<\/p>\n<\/p>\n<p><h4>1. \u6309\u94ae\uff08Button\uff09<\/h4>\n<\/p>\n<p><p>\u6309\u94ae\u662f\u7528\u4e8e\u89e6\u53d1\u4e8b\u4ef6\u7684\u7ec4\u4ef6\u3002\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e\u56de\u8c03\u51fd\u6570\u6765\u6307\u5b9a\u6309\u94ae\u88ab\u70b9\u51fb\u65f6\u8c03\u7528\u7684\u51fd\u6570\u3002\u6309\u94ae\u7684\u5916\u89c2\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e\u6587\u672c\u3001\u989c\u8272\u7b49\u5c5e\u6027\u6765\u8c03\u6574\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from kivy.app import App<\/p>\n<p>from kivy.uix.button import Button<\/p>\n<p>class MyApp(App):<\/p>\n<p>    def build(self):<\/p>\n<p>        return Button(text=&#39;Hello, World!&#39;)<\/p>\n<p>MyApp().run()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2. \u6807\u7b7e\uff08Label\uff09<\/h4>\n<\/p>\n<p><p>\u6807\u7b7e\u7528\u4e8e\u663e\u793a\u6587\u672c\uff0c\u662f\u6700\u57fa\u672c\u7684\u7ec4\u4ef6\u4e4b\u4e00\u3002\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e\u6587\u672c\u3001\u5b57\u4f53\u3001\u989c\u8272\u7b49\u5c5e\u6027\u6765\u6539\u53d8\u6807\u7b7e\u7684\u5916\u89c2\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from kivy.app import App<\/p>\n<p>from kivy.uix.label import Label<\/p>\n<p>class MyApp(App):<\/p>\n<p>    def build(self):<\/p>\n<p>        return Label(text=&#39;Hello, World!&#39;)<\/p>\n<p>MyApp().run()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u5341\u4e00\u3001Kivy\u5e03\u5c40\u7ba1\u7406<\/h3>\n<\/p>\n<p><p>Kivy\u63d0\u4f9b\u4e86\u591a\u79cd\u5e03\u5c40\u7ba1\u7406\u5668\uff0c\u5982\u76d2\u5b50\u5e03\u5c40\u3001\u7f51\u683c\u5e03\u5c40\u3001\u951a\u5e03\u5c40\u7b49\u3002\u6bcf\u79cd\u5e03\u5c40\u7ba1\u7406\u5668\u90fd\u6709\u5176\u7279\u5b9a\u7684\u7528\u9014\u548c\u4f18\u52bf\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u6839\u636e\u5177\u4f53\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u5e03\u5c40\u7ba1\u7406\u5668\u3002<\/p>\n<\/p>\n<p><h4>1. \u76d2\u5b50\u5e03\u5c40\uff08BoxLayout\uff09<\/h4>\n<\/p>\n<p><p>\u76d2\u5b50\u5e03\u5c40\u7528\u4e8e\u5c06\u7ec4\u4ef6\u6c34\u5e73\u6216\u5782\u76f4\u6392\u5217\u3002\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e\u7ec4\u4ef6\u7684\u586b\u5145\u65b9\u5f0f\u6765\u8c03\u6574\u7ec4\u4ef6\u7684\u6392\u5217\u65b9\u5411\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from kivy.app import App<\/p>\n<p>from kivy.uix.button import Button<\/p>\n<p>from kivy.uix.boxlayout import BoxLayout<\/p>\n<p>class MyApp(App):<\/p>\n<p>    def build(self):<\/p>\n<p>        layout = BoxLayout(orientation=&#39;horizontal&#39;)<\/p>\n<p>        button1 = Button(text=&#39;Button 1&#39;)<\/p>\n<p>        layout.add_widget(button1)<\/p>\n<p>        button2 = Button(text=&#39;Button 2&#39;)<\/p>\n<p>        layout.add_widget(button2)<\/p>\n<p>        return layout<\/p>\n<p>MyApp().run()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2. \u7f51\u683c\u5e03\u5c40\uff08GridLayout\uff09<\/h4>\n<\/p>\n<p><p>\u7f51\u683c\u5e03\u5c40\u5141\u8bb8\u5f00\u53d1\u8005\u5c06\u7ec4\u4ef6\u6392\u5217\u5728\u7f51\u683c\u4e2d\u3002\u53ef\u4ee5\u901a\u8fc7\u6307\u5b9a\u884c\u548c\u5217\u7684\u4f4d\u7f6e\u6765\u7cbe\u786e\u63a7\u5236\u7ec4\u4ef6\u7684\u4f4d\u7f6e\u3002\u7f51\u683c\u5e03\u5c40\u9002\u5408\u9700\u8981\u7cbe\u786e\u63a7\u5236\u7ec4\u4ef6\u4f4d\u7f6e\u7684\u573a\u666f\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from kivy.app import App<\/p>\n<p>from kivy.uix.button import Button<\/p>\n<p>from kivy.uix.gridlayout import GridLayout<\/p>\n<p>class MyApp(App):<\/p>\n<p>    def build(self):<\/p>\n<p>        layout = GridLayout(cols=2)<\/p>\n<p>        button1 = Button(text=&#39;Button 1&#39;)<\/p>\n<p>        layout.add_widget(button1)<\/p>\n<p>        button2 = Button(text=&#39;Button 2&#39;)<\/p>\n<p>        layout.add_widget(button2)<\/p>\n<p>        return layout<\/p>\n<p>MyApp().run()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u5341\u4e8c\u3001\u4e8b\u4ef6\u5904\u7406<\/h3>\n<\/p>\n<p><p>\u4e8b\u4ef6\u5904\u7406\u662fGUI\u5e94\u7528\u7684\u91cd\u8981\u90e8\u5206\uff0c\u5b83\u51b3\u5b9a\u4e86\u5e94\u7528\u5982\u4f55\u54cd\u5e94\u7528\u6237\u7684\u64cd\u4f5c\u3002Kivy\u901a\u8fc7\u4e8b\u4ef6\u7ed1\u5b9a\u6765\u5b9e\u73b0\u4e8b\u4ef6\u5904\u7406\u3002<\/p>\n<\/p>\n<p><h4>1. \u7ed1\u5b9a\u4e8b\u4ef6<\/h4>\n<\/p>\n<p><p>\u53ef\u4ee5\u901a\u8fc7\u7ed1\u5b9a\u4e8b\u4ef6\u6765\u5904\u7406\u7528\u6237\u7684\u4ea4\u4e92\u3002\u4e8b\u4ef6\u53ef\u4ee5\u662f\u9f20\u6807\u70b9\u51fb\u3001\u952e\u76d8\u6309\u952e\u7b49\u3002\u5904\u7406\u51fd\u6570\u53ef\u4ee5\u63a5\u6536\u4e8b\u4ef6\u5bf9\u8c61\u4f5c\u4e3a\u53c2\u6570\uff0c\u4ee5\u83b7\u53d6\u4e8b\u4ef6\u7684\u8be6\u7ec6\u4fe1\u606f\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from kivy.app import App<\/p>\n<p>from kivy.uix.button import Button<\/p>\n<p>class MyApp(App):<\/p>\n<p>    def build(self):<\/p>\n<p>        button = Button(text=&#39;Click Me&#39;)<\/p>\n<p>        button.bind(on_press=self.on_click)<\/p>\n<p>        return button<\/p>\n<p>    def on_click(self, instance):<\/p>\n<p>        print(&#39;Button clicked!&#39;)<\/p>\n<p>MyApp().run()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2. \u4f7f\u7528\u56de\u8c03\u51fd\u6570<\/h4>\n<\/p>\n<p><p>\u5bf9\u4e8e\u6309\u94ae\u7b49\u7ec4\u4ef6\uff0c\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e\u56de\u8c03\u51fd\u6570\u6765\u6307\u5b9a\u4e8b\u4ef6\u5904\u7406\u51fd\u6570\u3002\u8fd9\u79cd\u65b9\u5f0f\u9002\u5408\u7b80\u5355\u7684\u4e8b\u4ef6\u5904\u7406\u573a\u666f\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from kivy.app import App<\/p>\n<p>from kivy.uix.button import Button<\/p>\n<p>class MyApp(App):<\/p>\n<p>    def build(self):<\/p>\n<p>        return Button(text=&#39;Click Me&#39;, on_press=self.on_click)<\/p>\n<p>    def on_click(self, instance):<\/p>\n<p>        print(&#39;Button clicked!&#39;)<\/p>\n<p>MyApp().run()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u5341\u4e09\u3001wxPython\u57fa\u7840\u4ecb\u7ecd<\/h3>\n<\/p>\n<p><p>wxPython\u662f\u57fa\u4e8eC++\u7684wxWidgets\u5e93\u7684Python\u7ed1\u5b9a\uff0c\u7528\u4e8e\u521b\u5efa\u8de8\u5e73\u53f0\u7684\u684c\u9762\u5e94\u7528\u7a0b\u5e8f\u3002\u5b83\u63d0\u4f9b\u4e86\u539f\u751f\u7684\u7a97\u53e3\u548c\u63a7\u4ef6\uff0c\u4f7f\u5f97\u5e94\u7528\u7a0b\u5e8f\u5728\u5404\u4e2a\u5e73\u53f0\u4e0a\u90fd\u80fd\u5177\u6709\u4e00\u81f4\u7684\u5916\u89c2\u548c\u884c\u4e3a\u3002<\/p>\n<\/p>\n<p><p>wxPython\u7684\u4e3b\u8981\u4f18\u52bf\u5728\u4e8e\u5176\u539f\u751f\u98ce\u683c\u548c\u8de8\u5e73\u53f0\u80fd\u529b\u3002\u5b83\u63d0\u4f9b\u4e86\u4e0e\u539f\u751f\u7cfb\u7edf\u63a7\u4ef6\u4e00\u81f4\u7684\u5916\u89c2\uff0c\u4f7f\u5f97\u5e94\u7528\u7a0b\u5e8f\u5728\u5404\u4e2a\u5e73\u53f0\u4e0a\u90fd\u80fd\u65e0\u7f1d\u96c6\u6210\u3002\u6b64\u5916\uff0cwxPython\u8fd8\u652f\u6301\u591a\u79cd\u9ad8\u7ea7\u529f\u80fd\uff0c\u5982\u56fe\u5f62\u7ed8\u5236\u3001\u8bbe\u5907\u4e0a\u4e0b\u6587\u3001\u4e8b\u4ef6\u5904\u7406\u7b49\u3002<\/p>\n<\/p>\n<p><h3>\u5341\u56db\u3001wxPython\u7684\u57fa\u672c\u7ec4\u4ef6<\/h3>\n<\/p>\n<p><p>wxPython\u63d0\u4f9b\u4e86\u591a\u79cd\u57fa\u672c\u7ec4\u4ef6\uff0c\u5982\u6309\u94ae\u3001\u6807\u7b7e\u3001\u6587\u672c\u6846\u3001\u590d\u9009\u6846\u3001\u5355\u9009\u6309\u94ae\u3001\u5217\u8868\u6846\u7b49\u3002\u6bcf\u79cd\u7ec4\u4ef6\u90fd\u6709\u5176\u7279\u5b9a\u7684\u7528\u9014\u548c\u5c5e\u6027\uff0c\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e\u4e0d\u540c\u7684\u5c5e\u6027\u6765\u81ea\u5b9a\u4e49\u7ec4\u4ef6\u7684\u5916\u89c2\u548c\u884c\u4e3a\u3002<\/p>\n<\/p>\n<p><h4>1. \u6807\u7b7e\uff08wx.StaticText\uff09<\/h4>\n<\/p>\n<p><p>\u6807\u7b7e\u7528\u4e8e\u663e\u793a\u6587\u672c\uff0c\u662f\u6700\u57fa\u672c\u7684\u7ec4\u4ef6\u4e4b\u4e00\u3002\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e\u6587\u672c\u3001\u5b57\u4f53\u3001\u989c\u8272\u7b49\u5c5e\u6027\u6765\u6539\u53d8\u6807\u7b7e\u7684\u5916\u89c2\u3002\u521b\u5efa\u6807\u7b7e\u975e\u5e38\u7b80\u5355\uff0c\u53ea\u9700\u5b9e\u4f8b\u5316<code>wx.StaticText<\/code>\u7c7b\u5e76\u6307\u5b9a\u76f8\u5e94\u7684\u5c5e\u6027\u5373\u53ef\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import wx<\/p>\n<p>app = wx.App(False)<\/p>\n<p>frame = wx.Frame(None, wx.ID_ANY, &quot;Hello, World!&quot;)<\/p>\n<p>text = wx.StaticText(frame, label=&quot;Hello, World!&quot;)<\/p>\n<p>frame.Show(True)<\/p>\n<p>app.MainLoop()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2. \u6309\u94ae\uff08wx.Button\uff09<\/h4>\n<\/p>\n<p><p>\u6309\u94ae\u662f\u7528\u4e8e\u89e6\u53d1\u4e8b\u4ef6\u7684\u7ec4\u4ef6\u3002\u53ef\u4ee5\u901a\u8fc7\u7ed1\u5b9a\u70b9\u51fb\u4e8b\u4ef6\u6765\u6307\u5b9a\u6309\u94ae\u88ab\u70b9\u51fb\u65f6\u8c03\u7528\u7684\u51fd\u6570\u3002\u6309\u94ae\u7684\u5916\u89c2\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e\u6587\u672c\u3001\u989c\u8272\u7b49\u5c5e\u6027\u6765\u8c03\u6574\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import wx<\/p>\n<p>def on_click(event):<\/p>\n<p>    print(&quot;Button clicked!&quot;)<\/p>\n<p>app = wx.App(False)<\/p>\n<p>frame = wx.Frame(None, wx.ID_ANY, &quot;Button Example&quot;)<\/p>\n<p>button = wx.Button(frame, label=&quot;Click Me&quot;)<\/p>\n<p>button.Bind(wx.EVT_BUTTON, on_click)<\/p>\n<p>frame.Show(True)<\/p>\n<p>app.MainLoop()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u5341\u4e94\u3001wxPython\u5e03\u5c40\u7ba1\u7406<\/h3>\n<\/p>\n<p><p>wxPython\u63d0\u4f9b\u4e86\u591a\u79cd\u5e03\u5c40\u7ba1\u7406\u5668\uff0c\u5982\u76d2\u5b50\u5e03\u5c40\u3001\u7f51\u683c\u5e03\u5c40\u3001\u951a\u5e03\u5c40\u7b49\u3002\u6bcf\u79cd\u5e03\u5c40\u7ba1\u7406\u5668\u90fd\u6709\u5176\u7279\u5b9a\u7684\u7528\u9014\u548c\u4f18\u52bf\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u6839\u636e\u5177\u4f53\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u5e03\u5c40\u7ba1\u7406\u5668\u3002<\/p>\n<\/p>\n<p><h4>1. \u76d2\u5b50\u5e03\u5c40\uff08wx.BoxSizer\uff09<\/h4>\n<\/p>\n<p><p>\u76d2\u5b50\u5e03\u5c40\u7528\u4e8e\u5c06\u7ec4\u4ef6\u6c34\u5e73\u6216\u5782\u76f4\u6392\u5217\u3002\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e\u7ec4\u4ef6\u7684\u586b\u5145\u65b9\u5f0f\u6765\u8c03\u6574\u7ec4\u4ef6\u7684\u6392\u5217\u65b9\u5411\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import wx<\/p>\n<p>app = wx.App(False)<\/p>\n<p>frame = wx.Frame(None, wx.ID_ANY, &quot;BoxSizer Example&quot;)<\/p>\n<p>sizer = wx.BoxSizer(wx.HORIZONTAL)<\/p>\n<p>button1 = wx.Button(frame, label=&quot;Button 1&quot;)<\/p>\n<p>sizer.Add(button1, 0, wx.ALL, 5)<\/p>\n<p>button2 = wx.Button(frame, label=&quot;Button 2&quot;)<\/p>\n<p>sizer.Add(button2, 0, wx.ALL, 5)<\/p>\n<p>frame.SetSizer(sizer)<\/p>\n<p>frame.Show(True)<\/p>\n<p>app.MainLoop()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2. \u7f51\u683c\u5e03\u5c40\uff08wx.GridSizer\uff09<\/h4>\n<\/p>\n<p><p>\u7f51\u683c\u5e03\u5c40\u5141\u8bb8\u5f00\u53d1\u8005\u5c06\u7ec4\u4ef6\u6392\u5217\u5728\u7f51\u683c\u4e2d\u3002\u53ef\u4ee5\u901a\u8fc7\u6307\u5b9a\u884c\u548c\u5217\u7684\u4f4d\u7f6e\u6765\u7cbe\u786e\u63a7\u5236\u7ec4\u4ef6\u7684\u4f4d\u7f6e\u3002\u7f51\u683c\u5e03\u5c40\u9002\u5408\u9700\u8981\u7cbe\u786e\u63a7\u5236\u7ec4\u4ef6\u4f4d\u7f6e\u7684\u573a\u666f\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import wx<\/p>\n<p>app = wx.App(False)<\/p>\n<p>frame = wx.Frame(None, wx.ID_ANY, &quot;GridSizer Example&quot;)<\/p>\n<p>sizer = wx.GridSizer(rows=1, cols=2, hgap=5, vgap=5)<\/p>\n<p>button1 = wx.Button(frame, label=&quot;Button 1&quot;)<\/p>\n<p>sizer.Add(button1, 0, wx.EXPAND)<\/p>\n<p>button2 = wx.Button(frame, label=&quot;Button 2&quot;)<\/p>\n<p>sizer.Add(button2, 0, wx.EXPAND)<\/p>\n<p>frame.SetSizer(sizer)<\/p>\n<p>frame.Show(True)<\/p>\n<p>app.MainLoop()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u5341\u516d\u3001\u4e8b\u4ef6\u5904\u7406<\/h3>\n<\/p>\n<p><p>\u4e8b\u4ef6\u5904\u7406\u662fGUI\u5e94\u7528\u7684\u91cd\u8981\u90e8\u5206\uff0c\u5b83\u51b3\u5b9a\u4e86\u5e94\u7528\u5982\u4f55\u54cd\u5e94\u7528\u6237\u7684\u64cd\u4f5c\u3002wxPython\u901a\u8fc7\u4e8b\u4ef6\u7ed1\u5b9a\u6765\u5b9e\u73b0\u4e8b\u4ef6\u5904\u7406\u3002<\/p>\n<\/p>\n<p><h4>1. \u7ed1\u5b9a\u4e8b\u4ef6<\/h4>\n<\/p>\n<p><p>\u53ef\u4ee5\u901a\u8fc7\u7ed1\u5b9a\u4e8b\u4ef6\u6765\u5904\u7406\u7528\u6237<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>Python\u5f00\u53d1Windows\u754c\u9762\u9700\u8981\u54ea\u4e9b\u5de5\u5177\u548c\u5e93\uff1f<\/strong><br \/>\u5728\u5f00\u53d1Windows\u754c\u9762\u5e94\u7528\u65f6\uff0c\u5e38\u7528\u7684\u5de5\u5177\u548c\u5e93\u5305\u62ecTkinter\u3001PyQt\u3001wxPython\u548cKivy\u7b49\u3002Tkinter\u662fPython\u81ea\u5e26\u7684\u6807\u51c6GUI\u5e93\uff0c\u9002\u5408\u7b80\u5355\u7684\u754c\u9762\u5f00\u53d1\u3002PyQt\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u529f\u80fd\u548c\u7ec4\u4ef6\uff0c\u9002\u5408\u5f00\u53d1\u590d\u6742\u7684\u5e94\u7528\u7a0b\u5e8f\u3002wxPython\u5219\u662f\u4e00\u4e2a\u8de8\u5e73\u53f0\u7684GUI\u5de5\u5177\u5305\uff0c\u80fd\u591f\u521b\u5efa\u539f\u751f\u5916\u89c2\u7684\u5e94\u7528\u3002Kivy\u5219\u9002\u5408\u5f00\u53d1\u591a\u70b9\u89e6\u63a7\u7684\u5e94\u7528\uff0c\u652f\u6301\u591a\u79cd\u5e73\u53f0\u3002<\/p>\n<p><strong>\u5982\u4f55\u9009\u62e9\u5408\u9002\u7684GUI\u6846\u67b6\u8fdb\u884c\u5f00\u53d1\uff1f<\/strong><br \/>\u9009\u62e9\u5408\u9002\u7684GUI\u6846\u67b6\u4e3b\u8981\u53d6\u51b3\u4e8e\u9879\u76ee\u7684\u9700\u6c42\u3001\u5f00\u53d1\u8005\u7684\u719f\u6089\u7a0b\u5ea6\u4ee5\u53ca\u5e94\u7528\u7684\u590d\u6742\u6027\u3002\u5982\u679c\u9700\u8981\u5feb\u901f\u5f00\u53d1\u7b80\u5355\u5e94\u7528\uff0cTkinter\u662f\u4e00\u4e2a\u4e0d\u9519\u7684\u9009\u62e9\u3002\u5982\u679c\u9879\u76ee\u9700\u8981\u590d\u6742\u7684\u754c\u9762\u548c\u529f\u80fd\uff0cPyQt\u53ef\u80fd\u66f4\u4e3a\u5408\u9002\u3002\u6b64\u5916\uff0c\u8003\u8651\u5230\u672a\u6765\u7684\u53ef\u7ef4\u62a4\u6027\u548c\u6269\u5c55\u6027\uff0c\u4e86\u89e3\u6bcf\u4e2a\u6846\u67b6\u7684\u793e\u533a\u652f\u6301\u548c\u6587\u6863\u4e5f\u5f88\u91cd\u8981\u3002<\/p>\n<p><strong>\u5728Windows\u4e0a\u4f7f\u7528Python\u5f00\u53d1GUI\u5e94\u7528\u65f6\uff0c\u5982\u4f55\u5904\u7406\u4e8b\u4ef6\u548c\u56de\u8c03\uff1f<\/strong><br \/>\u5728Python\u7684GUI\u6846\u67b6\u4e2d\uff0c\u4e8b\u4ef6\u5904\u7406\u901a\u5e38\u901a\u8fc7\u7ed1\u5b9a\u4e8b\u4ef6\u5230\u7279\u5b9a\u7684\u56de\u8c03\u51fd\u6570\u6765\u5b9e\u73b0\u3002\u4f8b\u5982\uff0c\u5728Tkinter\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528<code>widget.bind(&#39;&lt;event&gt;&#39;, callback)<\/code>\u6765\u7ed1\u5b9a\u4e8b\u4ef6\u3002\u5728PyQt\u4e2d\uff0c\u4fe1\u53f7\u548c\u69fd\u673a\u5236\u7528\u4e8e\u4e8b\u4ef6\u5904\u7406\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u5b9a\u4e49\u69fd\u51fd\u6570\u5e76\u901a\u8fc7<code>signal.connect(slot)<\/code>\u6765\u5173\u8054\u4fe1\u53f7\u4e0e\u69fd\u3002\u7406\u89e3\u8fd9\u4e9b\u673a\u5236\u5bf9\u4e8e\u521b\u5efa\u54cd\u5e94\u5f0f\u7528\u6237\u754c\u9762\u81f3\u5173\u91cd\u8981\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\u5f00\u53d1Windows\u754c\u9762\u7684\u65b9\u6cd5\u6709\u591a\u79cd\uff0c\u5e38\u89c1\u7684\u65b9\u6cd5\u6709\u4f7f\u7528Tkinter\u3001PyQt\u3001Kivy\u3001wxP [&hellip;]","protected":false},"author":3,"featured_media":1018169,"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\/1018165"}],"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=1018165"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1018165\/revisions"}],"predecessor-version":[{"id":1018174,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1018165\/revisions\/1018174"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1018169"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1018165"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1018165"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1018165"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}