{"id":1748,"date":"2025-09-15T10:13:32","date_gmt":"2025-09-15T01:13:32","guid":{"rendered":"https:\/\/twarelab.com\/?p=1748"},"modified":"2025-09-12T10:31:38","modified_gmt":"2025-09-12T01:31:38","slug":"python-gui-program-development-tutorial","status":"publish","type":"post","link":"https:\/\/twarelab.com\/en\/blog\/python-gui-program-development-tutorial\/","title":{"rendered":"[Python] <strong>GUI \ud504\ub85c\uadf8\ub7a8 \uac1c\ubc1c \uc808\ucc28 \ud29c\ud1a0\ub9ac\uc5bc<\/strong>"},"content":{"rendered":"<p>Want to build a GUI program with Python but not sure where to start? &nbsp;<\/p>\n\n\n\n<p class=\"translation-block\">This post walks you through the entire process of creating a GUI application using <strong>PySide6<\/strong>.<\/p>\n\n\n\n<p>From designing the interface to wiring up events, you\u2019ll learn everything step by step!<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>1. Designing the UI with QtDesigner<\/strong><\/h2>\n\n\n\n<p class=\"translation-block\">Start by designing the look and feel of your application using <strong>QtDesigner<\/strong>.<\/p>\n\n\n\n<p>You can easily drag and drop widgets like buttons and text boxes, then save the layout as a `.ui` file.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>2. Converting the UI File to Python Code<\/strong><\/h2>\n\n\n\n<p>To use the `.ui` file in Python, you need to convert it. &nbsp;<\/p>\n\n\n\n<p>Run the following command in your terminal:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"bash\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">pyside6-uic xxx.ui -o xxx.py<\/pre>\n\n\n\n<p>This generates a Python file that contains your UI layout.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>3. Integrating the UI into MainWindow<\/strong><\/h2>\n\n\n\n<p>Now let\u2019s create the main window of your application:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">from PySide6.QtWidgets import QMainWindow \nfrom ui.ui_main import Ui_MainWindow\n\nclass MainWindow(QMainWindow): \n    def init(self): \n        super(MainWindow, self).init() self.ui = Ui_MainWindow() \n        self.ui.setupUi(self) \n        self.setWindowTitle(\"PLC Emulator v1.0\") self.show() <\/pre>\n\n\n\n<p>The setupUi(self) method connects the UI elements to the main window.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>4. Running the Application<\/strong><\/h2>\n\n\n\n<p>Time to launch your app! Create a main.py file and write:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">from PySide6.QtWidgets import QApplication \nfrom ui.MainWindow import MainWindow \nimport sys\n\nif name == 'main': \n    app = QApplication(sys.argv) \n    window = MainWindow() \n    sys.exit(app.exec()) <\/pre>\n\n\n\n<p>Then run it with:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"bash\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">python main.py <\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>5. Registering Events for Buttons and Controls<\/strong><\/h2>\n\n\n\n<p>To make your UI interactive, connect events to your widgets. For example, to trigger an action when a refresh button is clicked:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">class MainWindow(QMainWindow):\n     def __init__(self):\n         ...\n         self.ui.pushButton_refresh.clicked.connect(self.refreshPressed) \n         ...\n\n\n     def refreshPressed(self): \n         print(\"refreshPressed was invoked\") <\/pre>\n\n\n\n<p>Now clicking the button will call the refreshPressed function!<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Wrapping Up<\/strong><\/h2>\n\n\n\n<p>By following this tutorial, you can build a complete PySide6-based GUI application from scratch. Design your interface, wire up the logic, and bring your ideas to life!<\/p>","protected":false},"excerpt":{"rendered":"<p>A step-by-step guide to building a Python GUI application using PySide6, from UI design to event handling.<\/p>","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":true,"template":"","format":"standard","meta":{"_themeisle_gutenberg_block_has_review":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1,13,12],"tags":[86,84,83,82,85],"class_list":["post-1748","post","type-post","status-publish","format-standard","hentry","category-blog","category-en","category-ko","tag-event","tag-gui","tag-pyside6","tag-pytho","tag-tutorial"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/twarelab.com\/en\/wp-json\/wp\/v2\/posts\/1748","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/twarelab.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/twarelab.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/twarelab.com\/en\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/twarelab.com\/en\/wp-json\/wp\/v2\/comments?post=1748"}],"version-history":[{"count":4,"href":"https:\/\/twarelab.com\/en\/wp-json\/wp\/v2\/posts\/1748\/revisions"}],"predecessor-version":[{"id":1754,"href":"https:\/\/twarelab.com\/en\/wp-json\/wp\/v2\/posts\/1748\/revisions\/1754"}],"wp:attachment":[{"href":"https:\/\/twarelab.com\/en\/wp-json\/wp\/v2\/media?parent=1748"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/twarelab.com\/en\/wp-json\/wp\/v2\/categories?post=1748"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/twarelab.com\/en\/wp-json\/wp\/v2\/tags?post=1748"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}