์ƒˆ์†Œ์‹

๐Ÿ ํŒŒ์ด์ฌ (Python)

<PyQt5> Python Gui ์ธํ„ฐํŽ˜์ด์Šค ์ƒ์„ฑ ์„ค์น˜ ๋ฐฉ๋ฒ• ๋ฐ ์‚ฌ์šฉ๋ฒ•

  • -

tkinter๋Š” ์Šคํฌ๋ฆฝํŠธ์ž‘์„ฑ์„ ํ†ตํ•ด์„œ๋งŒ ์‹คํ–‰ ๊ฐ€๋Šฅํ•˜์ง€๋งŒ, PyQt5๋Š” Designer๋ผ๋Š” tool๋„ ๊ฐ™์ด ์ œ๊ณต๋˜์–ด ๋” ์ž‘์„ฑํ•˜๊ธฐ ํŽธ๋ฆฌํ•ฉ๋‹ˆ๋‹ค.

*PyQt5 Designer

 ์œ„ ํ™”๋ฉด์˜ ํ”„๋กœ๊ทธ๋žจ์—์„œ ๋“œ๋ž˜๊ทธ๋ฅผ ํ†ตํ•ด ์œ„์ ฏ๊ณผ ๊ธฐ๋Šฅ์„ ๋ฐฐ์น˜ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค. ๊ทธ ํ›„์— .uiํ™•์žฅ์ž๋ฅผ ๊ฐ€์ง„ (XMLํŒŒ์ผ)๋กœ ์ €์žฅ์ด ๋˜๋ฉฐ, ํŒŒ์ด์ฌ ํ„ฐ๋ฏธ๋„์ฐฝ์—์„œ Converter๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ .py ํŒŒ์ผ๋กœ ๋ณ€ํ™˜ํ•˜์—ฌ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

 

*PyQt5 ์„ค์น˜๋ฐฉ๋ฒ•

pip install pyqt5

pip install pyqt5-tools (ํˆด ์„ค์น˜)

 

๋‹ค์Œ ํŒŒ์ด์ฌ์˜ ์„ค์น˜๊ฒฝ๋กœ๋ฅผ ์ฐพ์•„ ๋“ค์–ด๊ฐ€๋ฉด, pyqt-tools\Qt\bin ํด๋”์— Designer ์‹คํ–‰ํŒŒ์ผ์ด ์žˆ์Šต๋‹ˆ๋‹ค.

์ € ๊ฐ™์€ ๊ฒฝ์šฐ๋Š” ๊ฐ€์ƒํ™˜๊ฒฝ ์‚ฌ์šฉ์ค‘์ด๋ผ(C:\python_jy\jy\Lib\site-packages\pyqt5_tools\Qt\bin)์— ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค.

 

*์‚ฌ์šฉ๋ฒ• ๋ฐ ์˜ˆ์ œ pyuic5 ".uiํŒŒ์ผ๋ช…" -o ".pyํŒŒ์ผ๋ช…"

์•„์ง ๊ธฐ๋Šฅ์— ๋Œ€ํ•ด ํŒŒ์•…ํ•˜์ง€ ๋ชปํ•˜์˜€๊ธฐ ๋•Œ๋ฌธ์—, ์ด๊ฒƒ์ €๊ฒƒ ๋„ฃ์–ด๋ณด๊ณ  ํŒŒ์ผ์„ ์ €์žฅํ–ˆ์Šต๋‹ˆ๋‹ค.

๊ทธ ํ›„์— ๊ฐ™์€ ๊ฒฝ๋กœ์— python ํŒŒ์ผ์„ ํ•˜๋‚˜ ์ƒ์„ฑํ•ด์ค๋‹ˆ๋‹ค.

Ctrl + R : ๋ฏธ๋ฆฌ๋ณด๊ธฐ (์–ด๋– ํ•œ ๊ธฐ๋Šฅ์ธ์ง€ ์ž˜ ๋ชจ๋ฅผ๋•Œ ๋ฏธ๋ฆฌ ์‚ฌ์šฉํ•ด๋ณด๋ฉด ์•Œ๊ธฐ ์‰ฝ์Šต๋‹ˆ๋‹ค.)

๋‹ค์Œ

import sys
from PyQt5 import QtWidgets
from PyQt5 import uic
 
class Form(QtWidgets.QDialog):
    def __init__(self, parent=None):
        QtWidgets.QDialog.__init__(self, parent)
        self.ui = uic.loadUi("test.ui")   ##์ด๊ณณ์— designer์—์„œ ์ €์žฅํ•œ ํŒŒ์ผ๋ช…์„ ์ž…๋ ฅํ•ด์ค๋‹ˆ๋‹ค.
        self.ui.show()
 
if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    w = Form()
    sys.exit(app.exec())

์‹คํ–‰๋œ ๋ชจ์Šต

Contents

ํฌ์ŠคํŒ… ์ฃผ์†Œ๋ฅผ ๋ณต์‚ฌํ–ˆ์Šต๋‹ˆ๋‹ค

์ด ๊ธ€์ด ๋„์›€์ด ๋˜์—ˆ๋‹ค๋ฉด ๊ณต๊ฐ ๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค.