PyQt(5) - ์˜ˆ์ œ2

Gyeomiiยท2022๋…„ 6์›” 24์ผ
0

DDITPython

๋ชฉ๋ก ๋ณด๊ธฐ
10/18
post-thumbnail

๐Ÿ“Œ ๋ณ„์ฐ๊ธฐ

์ฝ”๋“œ

import sys
from PyQt5.QtWidgets import *
from PyQt5 import uic
import secrets

# UIํŒŒ์ผ ์—ฐ๊ฒฐ
form_class = uic.loadUiType("myQt08.ui")[0]

# ํ™”๋ฉด์„ ๋„์šฐ๋Š”๋ฐ ์‚ฌ์šฉ๋˜๋Š” Class ์„ ์–ธ
class WindowClass(QMainWindow, form_class):

    def __init__(self):
        super().__init__()
        self.setupUi(self)
        # ๋ฒ„ํŠผ์— ๊ธฐ๋Šฅ์„ ์—ฐ๊ฒฐํ•˜๋Š” ์ฝ”๋“œ
        self.pb.clicked.connect(self.star)
        self.qle2.returnPressed.connect(self.star)
        
    #pb๊ฐ€ ๋ˆŒ๋ฆฌ๋ฉด ์ž‘๋™ํ•  ํ•จ์ˆ˜
    def star(self) :
        txt1 = self.qle1.text()
        txt2 = self.qle2.text()
        num1 = int(txt1)
        num2 = int(txt2)
        
        txt = ""
        for i in range(num1,num2+1):
            txt += self.drawStar(i)
        
        self.qte.setText(txt)        
    def drawStar(self,cnt):
        ret=""
        for i in range(cnt):
            ret += "*"
        ret += "\n"
        return ret
            
if __name__ == "__main__":
    app = QApplication(sys.argv) 
    myWindow = WindowClass() 
    myWindow.show()
    app.exec_()

์‹คํ–‰ ๊ฒฐ๊ณผ

๐Ÿ“Œ ๋ฐฐ์ˆ˜์˜ ํ•ฉ ๊ตฌํ•˜๊ธฐ

์ฝ”๋“œ

import sys
from PyQt5.QtWidgets import *
from PyQt5 import uic

# UIํŒŒ์ผ ์—ฐ๊ฒฐ
form_class = uic.loadUiType("myQtA.ui")[0]

# ํ™”๋ฉด์„ ๋„์šฐ๋Š”๋ฐ ์‚ฌ์šฉ๋˜๋Š” Class ์„ ์–ธ
class WindowClass(QMainWindow, form_class):

    def __init__(self):
        super().__init__()
        self.setupUi(self)
        # ๋ฒ„ํŠผ์— ๊ธฐ๋Šฅ์„ ์—ฐ๊ฒฐํ•˜๋Š” ์ฝ”๋“œ
        self.pb.clicked.connect(self.calc)
        
    # pb๊ฐ€ ๋ˆŒ๋ฆฌ๋ฉด ์ž‘๋™ํ•  ํ•จ์ˆ˜
    def calc(self):
        txt1 = self.qle1.text()
        txt2 = self.qle2.text()
        txt3 = self.qle3.text()
       
        num1 = int(txt1)
        num2 = int(txt2)
        num3 = int(txt3)
        sumN = 0
        for i in range(num1, num2 + 1):
            if(i % num3 == 0):
                sumN += i
                
        result = str(sumN)
        
        self.qle4.setText(result)

if __name__ == "__main__":
    app = QApplication(sys.argv) 
    myWindow = WindowClass() 
    myWindow.show()
    app.exec_()

์‹คํ–‰ ๊ฒฐ๊ณผ

profile
๊น€์„ฑ๊ฒธ

0๊ฐœ์˜ ๋Œ“๊ธ€