python
,視窗軟體
,PyQt5
,tkinter
20200706 M20200716
參考:老師講義網頁:PyQt 實作
pip install PyQt5 #依了解此兩項僅為Python連接qt designer用
pip install pyqt5-tools #
安裝Qt Designer下載網址
安裝完成,執行Qt Designer,選取Main Window進入視窗UI設計界面。設計完後,存檔(檔案儲存附檔名為.ui的檔案),內容為xml格式的文字檔。
假設Qt Designer開發的UI介面,存檔黨名為 notepad.ui,則可用下列的py程式介接。(ui與py要放在同一資料夾下,vscode要切換到該資料夾下。)
import sys, os
from PyQt5.QtWidgets import QApplication, QMainWindow, QFileDialog
from PyQt5 import uic
form_class = uic.loadUiType("notepad.ui")[0]
# 載入PyQt Designer設計好的畫面()此處為 notepad.ui
class MainWindow(QMainWindow, form_class):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
self.setupUi(self)
self.status = self.statusBar()
self.status.showMessage("狀態: 等待使用者") # 設定狀態訊息
def saveFile(self, MainWindow):
pass
text=self.textEdit.toPlainText()
print(text)
options = QFileDialog.Options()
path, _ = QFileDialog.getSaveFileName(self, "Save file", "", "Text documents (*.txt);;All files (*.*)")
print(path)
with open(path,'w', encoding='utf-8') as f: #with:在此情境下處理資料
f.write(text)
def openFile(self):
path, _ = QFileDialog.getOpenFileName(self, "Open file", "", "Text documents (*.txt);;All files (*.*)")
with open(path, 'r', encoding='utf-8') as f:
text = f.read()
self.textEdit.setPlainText(text)
def newFile(self):
self.textEdit.setPlainText('')
if __name__ == "__main__":
app = QApplication(sys.argv)
Win = MainWindow()
Win.show()
sys.exit(app.exec_())
# S20200710 上課範例 製作notepad
20200606
參考:nter Pythn3 做簡單窗口視窗
什么是 tkinter 窗口
S20200606 By YTC
M20200710
or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Syncing