๐ ์ ํ๊ธฐ ๋ง๋ค๊ธฐ
์ฝ๋
import sys
from PyQt5.QtWidgets import *
from PyQt5 import uic
form_class = uic.loadUiType("myQt09.ui")[0]
class WindowClass(QMainWindow, form_class):
def __init__(self):
super().__init__()
self.setupUi(self)
self.pbGroup = QButtonGroup()
self.pbGroup.setExclusive(False)
self.pbGroup.buttonClicked[int].connect(self.dial)
self.pb_call.clicked.connect(self.call)
self.pbGroup.addButton(self.pb1,1)
self.pbGroup.addButton(self.pb2,2)
self.pbGroup.addButton(self.pb3,3)
self.pbGroup.addButton(self.pb4,4)
self.pbGroup.addButton(self.pb5,5)
self.pbGroup.addButton(self.pb6,6)
self.pbGroup.addButton(self.pb7,7)
self.pbGroup.addButton(self.pb8,8)
self.pbGroup.addButton(self.pb9,9)
self.pbGroup.addButton(self.pb0,0)
def dial(self, id):
for pb in self.pbGroup.buttons():
if pb is self.pbGroup.button(id):
txt = self.qle.text()
txt += pb.text()
self.qle.setText(txt)
def call(self):
QMessageBox.about(self, 'MyQt09 Calling alert', "Calling to %s"%(self.qle.text()))
if __name__ == "__main__":
app = QApplication(sys.argv)
myWindow = WindowClass()
myWindow.show()
app.exec_()
์ค๋ช
self.pbGroup = QButtonGroup()
self.pbGroup.setExclusive(False)
self.pbGroup.buttonClicked[int].connect(self.dial)
self.pb_call.clicked.connect(self.call)
- self.๊ทธ๋ฃน๋ช
= QButtonGroup()
- ๊ทธ๋ฃน๋ช
์ QButton์ ๋ด๋๋ค.
- self.๊ทธ๋ฃน๋ช
.buttonClicked[int].connect(self.๋ฉ์๋๋ช
)
self.pbGroup.addButton(self.pb1,1)
self.pbGroup.addButton(self.pb2,2)
self.pbGroup.addButton(self.pb3,3)
self.pbGroup.addButton(self.pb4,4)
self.pbGroup.addButton(self.pb5,5)
self.pbGroup.addButton(self.pb6,6)
self.pbGroup.addButton(self.pb7,7)
self.pbGroup.addButton(self.pb8,8)
self.pbGroup.addButton(self.pb9,9)
self.pbGroup.addButton(self.pb0,0)
- self.pbGroup.addButton(self.๋ฒํผ๋ช
, Id๊ฐ)
def dial(self, id):
for pb in self.pbGroup.buttons():
if pb is self.pbGroup.button(id):
txt = self.qle.text()
txt += pb.text()
self.qle.setText(txt)
- ๋ฒํผ๊ทธ๋ฃน์์ pb๊ฐ ๋๋ฆฌ๋ฉด ๋๋ฆฐ pb์ ์์ด๋์ ์กด์ฌํ๋ pb์ ์์ด๋๊ฐ ๊ฐ์ ๋ ๊ทธ ํ
์คํธ๊ฐ์ ๊ฐ์ ธ์จ๋ค.
์คํ ๊ฒฐ๊ณผ