PYTHON
PYQT 전화번호 누르기 + QMessageBox, sender()
9400
2023. 1. 2. 20:00

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>748</width>
<height>602</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="QPushButton" name="pb1">
<property name="geometry">
<rect>
<x>70</x>
<y>80</y>
<width>75</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>1</string>
</property>
</widget>
<widget class="QPushButton" name="pb2">
<property name="geometry">
<rect>
<x>160</x>
<y>80</y>
<width>75</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>2</string>
</property>
</widget>
<widget class="QPushButton" name="pb3">
<property name="geometry">
<rect>
<x>250</x>
<y>80</y>
<width>75</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>3</string>
</property>
</widget>
<widget class="QPushButton" name="pb4">
<property name="geometry">
<rect>
<x>70</x>
<y>110</y>
<width>75</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>4</string>
</property>
</widget>
<widget class="QPushButton" name="pb5">
<property name="geometry">
<rect>
<x>160</x>
<y>110</y>
<width>75</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>5</string>
</property>
</widget>
<widget class="QPushButton" name="pb6">
<property name="geometry">
<rect>
<x>250</x>
<y>110</y>
<width>75</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>6</string>
</property>
</widget>
<widget class="QPushButton" name="pb7">
<property name="geometry">
<rect>
<x>70</x>
<y>140</y>
<width>75</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>7</string>
</property>
</widget>
<widget class="QPushButton" name="pb8">
<property name="geometry">
<rect>
<x>160</x>
<y>140</y>
<width>75</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>8</string>
</property>
</widget>
<widget class="QPushButton" name="pb9">
<property name="geometry">
<rect>
<x>250</x>
<y>140</y>
<width>75</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>9</string>
</property>
</widget>
<widget class="QPushButton" name="pb0">
<property name="geometry">
<rect>
<x>70</x>
<y>170</y>
<width>75</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>0</string>
</property>
</widget>
<widget class="QPushButton" name="pbCall">
<property name="geometry">
<rect>
<x>160</x>
<y>170</y>
<width>161</width>
<height>21</height>
</rect>
</property>
<property name="text">
<string>CALL</string>
</property>
</widget>
<widget class="QLineEdit" name="le">
<property name="geometry">
<rect>
<x>80</x>
<y>30</y>
<width>241</width>
<height>31</height>
</rect>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>748</width>
<height>21</height>
</rect>
</property>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources/>
<connections/>
</ui>
코드
import sys
from PyQt5.QtWidgets import *
from PyQt5 import uic
form_class = uic.loadUiType("main08.ui")[0]
class WindowClass(QMainWindow, form_class) :
def __init__(self) :
super().__init__()
self.setupUi(self)
self.pb1.clicked.connect(self.myclick)
self.pb2.clicked.connect(self.myclick)
self.pb3.clicked.connect(self.myclick)
self.pb4.clicked.connect(self.myclick)
self.pb5.clicked.connect(self.myclick)
self.pb6.clicked.connect(self.myclick)
self.pb7.clicked.connect(self.myclick)
self.pb8.clicked.connect(self.myclick)
self.pb9.clicked.connect(self.myclick)
self.pb0.clicked.connect(self.myclick)
self.pbCall.clicked.connect(self.myCall)
def myCall(self):
str_tel = self.le.text()
QMessageBox.about(self,'calling',str_tel)
def myclick(self):
str_new = self.sender().text()
str_old = self.le.text()
self.le.setText(str_old+str_new)
print(str_new,str_old)
if __name__ == "__main__" :
#QApplication : 프로그램을 실행시켜주는 클래스
app = QApplication(sys.argv)
#WindowClass의 인스턴스 생성
myWindow = WindowClass()
#프로그램 화면을 보여주는 코드
myWindow.show()
#프로그램을 이벤트루프로 진입시키는(프로그램을 작동시키는) 코드
app.exec_()
