{"id":31733,"date":"2024-11-01T09:02:16","date_gmt":"2024-11-01T09:02:16","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=31733"},"modified":"2024-11-01T11:48:29","modified_gmt":"2024-11-01T11:48:29","slug":"creating-a-simple-notepad-with-python","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/31733\/","title":{"rendered":"Creating a Simple Notepad with Python"},"content":{"rendered":"\n<p>Hello, today we will create a simple Python notepad application. In this tutorial, we will build a GUI application using PyQt and cover how to save and load notes through file input and output. Through this, you will enhance your understanding of basic GUI programming and file handling in Python.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">1. Python GUI Programming<\/h2>\n\n\n\n<p>GUI stands for Graphical User Interface, which is a graphic-based interface that allows users to easily use the program. PyQt is one of the most widely used GUI toolkits in Python, providing powerful and diverse widgets. In this tutorial, we will create a simple notepad using PyQt5.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2. Installing Required Tools<\/h2>\n\n\n\n<p>First, we need to install PyQt5. Run the following command to install PyQt5:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pip install PyQt5<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">3. Setting Up Project Structure<\/h2>\n\n\n\n<p>We will set up the basic structure of the project. Create a project folder and create a file for the Python script:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mkdir python-notepad\ncd python-notepad\ntouch notepad.py<\/code><\/pre>\n\n\n\n<p>Now, let&#8217;s start coding.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">4. Creating GUI with PyQt5<\/h2>\n\n\n\n<p>When using PyQt5, you need to create a window using an instance of QWidget or its derived classes. The necessary elements to create a basic notepad interface are as follows:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>QTextEdit widget for text input<\/li>\n\n\n\n<li>Functionality to open and save files<\/li>\n\n\n\n<li>Convenient menu bar<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">4.1. Writing Basic Code<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>import sys\nfrom PyQt5.QtWidgets import QApplication, QMainWindow, QAction, QTextEdit, QFileDialog, QMessageBox\nfrom PyQt5.QtGui import QIcon\n\nclass Notepad(QMainWindow):\n    def __init__(self):\n        super().__init__()\n\n        # Create QTextEdit widget\n        self.textEdit = QTextEdit(self)\n        self.setCentralWidget(self.textEdit)\n\n        # Initial settings for the notepad\n        self.initUI()\n\n    def initUI(self):\n        # Create menu bar\n        menubar = self.menuBar()\n\n        # Create file menu\n        fileMenu = menubar.addMenu('File')\n\n        # Add open action\n        openFile = QAction(QIcon('open.png'), 'Open', self)\n        openFile.setShortcut('Ctrl+O')\n        openFile.setStatusTip('Open file')\n        openFile.triggered.connect(self.showDialog)\n        fileMenu.addAction(openFile)\n\n        # Add save action\n        saveFile = QAction(QIcon('save.png'), 'Save', self)\n        saveFile.setShortcut('Ctrl+S')\n        saveFile.setStatusTip('Save file')\n        saveFile.triggered.connect(self.saveFile)\n        fileMenu.addAction(saveFile)\n\n        # Add exit action\n        exitAction = QAction('Exit', self)\n        exitAction.setShortcut('Ctrl+Q')\n        exitAction.setStatusTip('Exit application')\n        exitAction.triggered.connect(self.close)\n        fileMenu.addAction(exitAction)\n\n        # Activate status bar\n        self.statusBar()\n\n        # Set up main window\n        self.setGeometry(300, 300, 600, 400)\n        self.setWindowTitle('Notepad')\n        self.show()\n\n    def showDialog(self):\n        fname, _ = QFileDialog.getOpenFileName(self, 'Open File', '\/', \"Text files (*.txt)\")\n        \n        if fname:\n            with open(fname, 'r', encoding='utf-8') as f:\n                self.textEdit.setText(f.read())\n\n    def saveFile(self):\n        fname, _ = QFileDialog.getSaveFileName(self, 'Save File', '\/', \"Text files (*.txt)\")\n        \n        if fname:\n            with open(fname, 'w', encoding='utf-8') as f:\n                f.write(self.textEdit.toPlainText())\n\nif __name__ == '__main__':\n    app = QApplication(sys.argv)\n    ex = Notepad()\n    sys.exit(app.exec_())\n    <\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">5. Code Analysis<\/h2>\n\n\n\n<p>The above code is a very basic PyQt5 application. With this code, you can implement a simple notepad feature that allows you to open, edit, and save files. Each part is composed as follows:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">5.1. Notepad Class<\/h3>\n\n\n\n<p>The Notepad class inherits from the QMainWindow class and is responsible for the main functionality of the window in the PyQt application. Here, we placed the QTextEdit widget in the center and added functionality to open and save files through the menu bar.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">5.2. initUI Method<\/h3>\n\n\n\n<p>This handles the initial UI setup of the notepad, creating the menu bar and status bar, and adding actions such as open, save, and exit to the menu. Each action is set up to call a specific method in response to user interaction.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">5.3. showDialog and saveFile Methods<\/h3>\n\n\n\n<p>The showDialog method reads the file selected by the user through the open file dialog and displays it in QTextEdit. The saveFile method saves the current text inputted in QTextEdit to the path specified by the user through the save file dialog.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">6. Conclusion<\/h2>\n\n\n\n<p>A basic Python notepad was created using PyQt5. This program implements simple functionality to open, edit, and save files. Through this, you learned the basic usage of PyQt5 and how to develop GUI applications using Python. With this basic notepad example, you will be able to create more complex and feature-rich applications. Be sure to enhance your skills through various practices!<\/p>\n\n\n\n<p>Thank you!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hello, today we will create a simple Python notepad application. In this tutorial, we will build a GUI application using PyQt and cover how to save and load notes through file input and output. Through this, you will enhance your understanding of basic GUI programming and file handling in Python. 1. Python GUI Programming GUI &hellip; <a href=\"https:\/\/atmokpo.com\/w\/31733\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;Creating a Simple Notepad with Python&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[98],"tags":[95],"class_list":["post-31733","post","type-post","status-publish","format-standard","hentry","category--en","tag--en"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Creating a Simple Notepad with Python - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/atmokpo.com\/w\/31733\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Creating a Simple Notepad with Python - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"Hello, today we will create a simple Python notepad application. In this tutorial, we will build a GUI application using PyQt and cover how to save and load notes through file input and output. Through this, you will enhance your understanding of basic GUI programming and file handling in Python. 1. Python GUI Programming GUI &hellip; \ub354 \ubcf4\uae30 &quot;Creating a Simple Notepad with Python&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/31733\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:02:16+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T11:48:29+00:00\" \/>\n<meta name=\"author\" content=\"root\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@bebubo4\" \/>\n<meta name=\"twitter:site\" content=\"@bebubo4\" \/>\n<meta name=\"twitter:label1\" content=\"\uae00\uc4f4\uc774\" \/>\n\t<meta name=\"twitter:data1\" content=\"root\" \/>\n\t<meta name=\"twitter:label2\" content=\"\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04\" \/>\n\t<meta name=\"twitter:data2\" content=\"3\ubd84\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/atmokpo.com\/w\/31733\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/31733\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"Creating a Simple Notepad with Python\",\"datePublished\":\"2024-11-01T09:02:16+00:00\",\"dateModified\":\"2024-11-01T11:48:29+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/31733\/\"},\"wordCount\":440,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"keywords\":[\"\ud30c\uc774\uc36c\uac15\uc88c\"],\"articleSection\":[\"Python Study\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/31733\/\",\"url\":\"https:\/\/atmokpo.com\/w\/31733\/\",\"name\":\"Creating a Simple Notepad with Python - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:02:16+00:00\",\"dateModified\":\"2024-11-01T11:48:29+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/31733\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/31733\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/31733\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Creating a Simple Notepad with Python\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/atmokpo.com\/w\/#website\",\"url\":\"https:\/\/atmokpo.com\/w\/\",\"name\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/atmokpo.com\/w\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"ko-KR\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\",\"name\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"url\":\"https:\/\/atmokpo.com\/w\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png\",\"contentUrl\":\"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png\",\"width\":400,\"height\":400,\"caption\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\"},\"image\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/bebubo4\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\",\"name\":\"root\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g\",\"caption\":\"root\"},\"sameAs\":[\"http:\/\/atmokpo.com\/w\"],\"url\":\"https:\/\/atmokpo.com\/w\/author\/root\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Creating a Simple Notepad with Python - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/atmokpo.com\/w\/31733\/","og_locale":"ko_KR","og_type":"article","og_title":"Creating a Simple Notepad with Python - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"Hello, today we will create a simple Python notepad application. In this tutorial, we will build a GUI application using PyQt and cover how to save and load notes through file input and output. Through this, you will enhance your understanding of basic GUI programming and file handling in Python. 1. Python GUI Programming GUI &hellip; \ub354 \ubcf4\uae30 \"Creating a Simple Notepad with Python\"","og_url":"https:\/\/atmokpo.com\/w\/31733\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:02:16+00:00","article_modified_time":"2024-11-01T11:48:29+00:00","author":"root","twitter_card":"summary_large_image","twitter_creator":"@bebubo4","twitter_site":"@bebubo4","twitter_misc":{"\uae00\uc4f4\uc774":"root","\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04":"3\ubd84"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/atmokpo.com\/w\/31733\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/31733\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"Creating a Simple Notepad with Python","datePublished":"2024-11-01T09:02:16+00:00","dateModified":"2024-11-01T11:48:29+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/31733\/"},"wordCount":440,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"keywords":["\ud30c\uc774\uc36c\uac15\uc88c"],"articleSection":["Python Study"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/31733\/","url":"https:\/\/atmokpo.com\/w\/31733\/","name":"Creating a Simple Notepad with Python - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:02:16+00:00","dateModified":"2024-11-01T11:48:29+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/31733\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/31733\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/31733\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"Creating a Simple Notepad with Python"}]},{"@type":"WebSite","@id":"https:\/\/atmokpo.com\/w\/#website","url":"https:\/\/atmokpo.com\/w\/","name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","description":"","publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/atmokpo.com\/w\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"ko-KR"},{"@type":"Organization","@id":"https:\/\/atmokpo.com\/w\/#organization","name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","url":"https:\/\/atmokpo.com\/w\/","logo":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/","url":"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png","contentUrl":"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png","width":400,"height":400,"caption":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8"},"image":{"@id":"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/bebubo4"]},{"@type":"Person","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7","name":"root","image":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g","caption":"root"},"sameAs":["http:\/\/atmokpo.com\/w"],"url":"https:\/\/atmokpo.com\/w\/author\/root\/"}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/31733","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/comments?post=31733"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/31733\/revisions"}],"predecessor-version":[{"id":31734,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/31733\/revisions\/31734"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=31733"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=31733"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=31733"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}