본문 바로가기
Python/Python 기초

파이썬(QT) 전화번호 팝업창 띄우기 예제

by 미눅스[멘토] 2023. 6. 28.
728x90

 

import sys
from PyQt5 import(uic)
from PyQt5.QtWidgets import QApplication, QMainWindow
import win32api


form_class = uic.loadUiType("myqt05.ui")[0]

class WindowClass(QMainWindow, form_class):
    def __init__(self):
        super().__init__()
        self.setupUi(self)

        self.pb0.clicked.connect(lambda :self.myclick(0))
        self.pb1.clicked.connect(lambda :self.myclick(1))
        self.pb2.clicked.connect(lambda :self.myclick(2))
        self.pb3.clicked.connect(lambda :self.myclick(3))
        self.pb4.clicked.connect(lambda :self.myclick(4))
        self.pb5.clicked.connect(lambda :self.myclick(5))
        self.pb6.clicked.connect(lambda :self.myclick(6))
        self.pb7.clicked.connect(lambda :self.myclick(7))
        self.pb8.clicked.connect(lambda :self.myclick(8))
        self.pb9.clicked.connect(lambda :self.myclick(9))
        self.pb_call.clicked.connect(lambda :self.myclick("call"))
        
    def myclick(self,i):
        # 자기자신을 self.sender()로 받는다
        # 나는 lamda: 로 받았다
        print(self.sender().text())
        
        if i=="call":
           a = self.le.text()
           win32api.MessageBox(0,a+"Calling..","전화연결중", 0)
        else:
            a = self.le.text()
            self.le.setText(a+str(i))
        
       
       
if __name__ == '__main__':
    app = QApplication(sys.argv)
    myWindow = WindowClass()
    myWindow.show()
    app.exec_()

 

 

결과

 

 

 


UI코드

<?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>800</width>
    <height>600</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>MainWindow</string>
  </property>
  <widget class="QWidget" name="centralwidget">
   <widget class="QLineEdit" name="le">
    <property name="geometry">
     <rect>
      <x>100</x>
      <y>50</y>
      <width>241</width>
      <height>31</height>
     </rect>
    </property>
   </widget>
   <widget class="QPushButton" name="pb3">
    <property name="geometry">
     <rect>
      <x>261</x>
      <y>101</y>
      <width>75</width>
      <height>23</height>
     </rect>
    </property>
    <property name="text">
     <string>3</string>
    </property>
   </widget>
   <widget class="QPushButton" name="pb2">
    <property name="geometry">
     <rect>
      <x>180</x>
      <y>101</y>
      <width>75</width>
      <height>23</height>
     </rect>
    </property>
    <property name="text">
     <string>2</string>
    </property>
   </widget>
   <widget class="QPushButton" name="pb1">
    <property name="geometry">
     <rect>
      <x>99</x>
      <y>101</y>
      <width>75</width>
      <height>23</height>
     </rect>
    </property>
    <property name="text">
     <string>1</string>
    </property>
   </widget>
   <widget class="QPushButton" name="pb4">
    <property name="geometry">
     <rect>
      <x>99</x>
      <y>130</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>180</x>
      <y>130</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>261</x>
      <y>130</y>
      <width>75</width>
      <height>23</height>
     </rect>
    </property>
    <property name="text">
     <string>6</string>
    </property>
   </widget>
   <widget class="QPushButton" name="pb8">
    <property name="geometry">
     <rect>
      <x>180</x>
      <y>159</y>
      <width>75</width>
      <height>23</height>
     </rect>
    </property>
    <property name="text">
     <string>8</string>
    </property>
   </widget>
   <widget class="QPushButton" name="pb7">
    <property name="geometry">
     <rect>
      <x>99</x>
      <y>159</y>
      <width>75</width>
      <height>23</height>
     </rect>
    </property>
    <property name="text">
     <string>7</string>
    </property>
   </widget>
   <widget class="QPushButton" name="pb9">
    <property name="geometry">
     <rect>
      <x>261</x>
      <y>159</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>100</x>
      <y>190</y>
      <width>75</width>
      <height>23</height>
     </rect>
    </property>
    <property name="text">
     <string>0</string>
    </property>
   </widget>
   <widget class="QPushButton" name="pb_call">
    <property name="geometry">
     <rect>
      <x>184</x>
      <y>190</y>
      <width>151</width>
      <height>23</height>
     </rect>
    </property>
    <property name="text">
     <string>CALL</string>
    </property>
   </widget>
  </widget>
  <widget class="QMenuBar" name="menubar">
   <property name="geometry">
    <rect>
     <x>0</x>
     <y>0</y>
     <width>800</width>
     <height>21</height>
    </rect>
   </property>
  </widget>
  <widget class="QStatusBar" name="statusbar"/>
 </widget>
 <resources/>
 <connections/>
</ui>