관리 메뉴

거니의 velog

231102_파이썬 기초 6 본문

대덕인재개발원/대덕인재개발원_파이썬 프로그래밍

231102_파이썬 기초 6

Unlimited00 2023. 11. 2. 08:49

[MySwing09.java]

package day04;

import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.JButton;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

public class MySwing09 extends JFrame {

	private JPanel contentPane;
	private JTextField tf;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					MySwing09 frame = new MySwing09();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public MySwing09() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 281, 258);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));

		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		tf = new JTextField();
		tf.setBounds(31, 24, 203, 21);
		contentPane.add(tf);
		tf.setColumns(10);
		tf.setHorizontalAlignment(SwingConstants.RIGHT);
		
		JButton btn1 = new JButton("1");
		btn1.setBounds(31, 55, 59, 23);
		contentPane.add(btn1);
		
		JButton btn2 = new JButton("2");
//		btn2.addMouseListener(new MouseAdapter() {
//			public void mouseClicked(MouseEvent e) {
//				JButton imsi = (JButton) e.getComponent();
////				JButton imsi2 = (JButton) e.getSource();
//				
////				System.out.println(imsi.getText());
////				System.out.println(imsi2.getText());
//			}
//		});
		btn2.setBounds(102, 55, 59, 23);
		contentPane.add(btn2);
		
		JButton btn3 = new JButton("3");
		btn3.setBounds(175, 55, 59, 23);
		contentPane.add(btn3);
		
		JButton btn4 = new JButton("4");
		btn4.setBounds(31, 91, 59, 23);
		contentPane.add(btn4);
		
		JButton btn5 = new JButton("5");
		btn5.setBounds(102, 91, 59, 23);
		contentPane.add(btn5);
		
		JButton btn6 = new JButton("6");
		btn6.setBounds(175, 91, 59, 23);
		contentPane.add(btn6);
		
		JButton btn7 = new JButton("7");
		btn7.setBounds(31, 124, 59, 23);
		contentPane.add(btn7);
		
		JButton btn8 = new JButton("8");
		btn8.setBounds(102, 124, 59, 23);
		contentPane.add(btn8);
		
		JButton btn9 = new JButton("9");
		btn9.setBounds(175, 124, 59, 23);
		contentPane.add(btn9);
		
		JButton btn_call = new JButton("☎");
		btn_call.setBounds(102, 157, 132, 23);
		contentPane.add(btn_call);
		
		JButton btn0 = new JButton("0");
		btn0.setBounds(31, 157, 59, 23);
		contentPane.add(btn0);
		
		btn1.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) {myclick(e);} });
		btn2.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) {myclick(e);} });
		btn3.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) {myclick(e);} });
		btn4.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) {myclick(e);} });
		btn5.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) {myclick(e);} });
		btn6.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) {myclick(e);} });
		btn7.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) {myclick(e);} });
		btn8.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) {myclick(e);} });
		btn9.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) {myclick(e);} });
		btn0.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) {myclick(e);} });
		
		btn_call.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) {mycall();} });
	}
	
	void myclick(MouseEvent e) {
		JButton temp = (JButton) e.getComponent();
		String str_new = temp.getText();
		String str_old = tf.getText();
		
		tf.setText(str_old + str_new);
	}
	
	void mycall() {
		String str_tel = tf.getText();
		JOptionPane.showMessageDialog(null, "calling\n" + str_tel);
	}

}


[day04.pyqt03]

import sys
from PyQt5 import uic
from PyQt5.QtWidgets import QApplication, QMainWindow
from PyQt5.Qt import QLineEdit

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

class MainClass(QMainWindow, form_class):
    def __init__(self) :
        QMainWindow.__init__(self)
        self.setupUi(self)
        self.pb.clicked.connect(self.myclick) # <widget class="QPushButton" name="pb">
        self.show()
        
    def myclick(self) :
        # pass
        a = self.te1.toPlainText()
        b = self.te2.toPlainText()
        
        aa = int(a)
        bb = int(b)
        
        min = aa - bb
        self.te3.setText(str(min))
        
if __name__ == "__main__" :
    app = QApplication(sys.argv) 
    window = MainClass() 
    app.exec_()


[day04.pyqt04]

import sys
from PyQt5 import uic
from PyQt5.QtWidgets import QApplication, QMainWindow
from PyQt5.Qt import QLineEdit
from random import random

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

class MainClass(QMainWindow, form_class):
    def __init__(self) :
        QMainWindow.__init__(self)
        self.setupUi(self)
        self.pb.clicked.connect(self.myclick) # <widget class="QPushButton" name="pb">
        self.show()
        
    def myclick(self) :
        # print("myclick")
        # pass
        arr = [
            1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
            11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
            21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
            31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
            41, 42, 43, 44, 45
        ]
        for i in range(1000):
            rnd = int(random() * 45)
            temp = arr[0]
            arr[0] = arr[rnd]
            arr[rnd] = temp
        self.pte1.setPlainText(str(arr[0]))
        self.pte2.setPlainText(str(arr[1]))
        self.pte3.setPlainText(str(arr[2]))
        self.pte4.setPlainText(str(arr[3]))
        self.pte5.setPlainText(str(arr[4]))
        self.pte6.setPlainText(str(arr[5]))
        
if __name__ == "__main__" :
    app = QApplication(sys.argv) 
    window = MainClass() 
    app.exec_()


[pyqt05.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>312</width>
    <height>236</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>MainWindow</string>
  </property>
  <widget class="QWidget" name="centralwidget">
   <widget class="QLabel" name="lbl_mine">
    <property name="geometry">
     <rect>
      <x>50</x>
      <y>30</y>
      <width>56</width>
      <height>12</height>
     </rect>
    </property>
    <property name="text">
     <string>나:</string>
    </property>
   </widget>
   <widget class="QLabel" name="lbl_com">
    <property name="geometry">
     <rect>
      <x>50</x>
      <y>70</y>
      <width>56</width>
      <height>12</height>
     </rect>
    </property>
    <property name="text">
     <string>컴:</string>
    </property>
   </widget>
   <widget class="QLabel" name="lbl_result">
    <property name="geometry">
     <rect>
      <x>50</x>
      <y>110</y>
      <width>56</width>
      <height>12</height>
     </rect>
    </property>
    <property name="text">
     <string>결과:</string>
    </property>
   </widget>
   <widget class="QLineEdit" name="le_mine">
    <property name="geometry">
     <rect>
      <x>150</x>
      <y>20</y>
      <width>113</width>
      <height>20</height>
     </rect>
    </property>
   </widget>
   <widget class="QLineEdit" name="le_com">
    <property name="geometry">
     <rect>
      <x>150</x>
      <y>60</y>
      <width>113</width>
      <height>20</height>
     </rect>
    </property>
   </widget>
   <widget class="QLineEdit" name="le_result">
    <property name="geometry">
     <rect>
      <x>150</x>
      <y>100</y>
      <width>113</width>
      <height>20</height>
     </rect>
    </property>
   </widget>
   <widget class="QPushButton" name="pb">
    <property name="geometry">
     <rect>
      <x>50</x>
      <y>150</y>
      <width>211</width>
      <height>23</height>
     </rect>
    </property>
    <property name="text">
     <string>게임하기</string>
    </property>
   </widget>
  </widget>
  <widget class="QMenuBar" name="menubar">
   <property name="geometry">
    <rect>
     <x>0</x>
     <y>0</y>
     <width>312</width>
     <height>21</height>
    </rect>
   </property>
  </widget>
  <widget class="QStatusBar" name="statusbar"/>
 </widget>
 <resources/>
 <connections/>
</ui>

[day04.pyqt05]

import sys
from PyQt5 import uic
from PyQt5.QtWidgets import QApplication, QMainWindow
from random import random

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

class MainClass(QMainWindow, form_class):
    def __init__(self) :
        QMainWindow.__init__(self)
        self.setupUi(self)
        self.pb.clicked.connect(self.myclick) # <widget class="QPushButton" name="pb">
        self.show()
        
    def myclick(self) :
        # pass
        mine = self.le_mine.text()
        com = ""
        result = ""
        # print(a)
        rnd = random()
        
        if(rnd > 0.5):
            com = "홀"
        else:
            com = "짝"
        
        if(mine == com):
            result = "이김"
        else:
            result = "짐"
            
        self.le_com.setText(com)
        self.le_result.setText(result)
        
if __name__ == "__main__" :
    app = QApplication(sys.argv) 
    window = MainClass() 
    app.exec_()


[day04.pyqt05]

import sys
from PyQt5 import uic
from PyQt5.QtWidgets import QApplication, QMainWindow
from random import random

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

class MainClass(QMainWindow, form_class):
    def __init__(self) :
        QMainWindow.__init__(self)
        self.setupUi(self)
        self.pb.clicked.connect(self.myclick) # <widget class="QPushButton" name="pb">
        self.le_mine.returnPressed.connect(self.myclick)
        self.show()
        
    def myclick(self) :
        # pass
        mine = self.le_mine.text()
        com = ""
        result = ""
        # print(a)
        rnd = random()
        
        if(rnd > 0.5):
            com = "홀"
        else:
            com = "짝"
        
        if(mine == com):
            result = "이김"
        else:
            result = "짐"
            
        self.le_com.setText(com)
        self.le_result.setText(result)
        
if __name__ == "__main__" :
    app = QApplication(sys.argv) 
    window = MainClass() 
    app.exec_()

- 엔터키를 치면 클릭 이벤트 발생


[pyqt06.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>323</width>
    <height>502</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>MainWindow</string>
  </property>
  <widget class="QWidget" name="centralwidget">
   <widget class="QSpinBox" name="sb">
    <property name="geometry">
     <rect>
      <x>70</x>
      <y>40</y>
      <width>51</width>
      <height>21</height>
     </rect>
    </property>
    <property name="value">
     <number>5</number>
    </property>
   </widget>
   <widget class="QPushButton" name="pb">
    <property name="geometry">
     <rect>
      <x>170</x>
      <y>40</y>
      <width>75</width>
      <height>23</height>
     </rect>
    </property>
    <property name="text">
     <string>출력하기</string>
    </property>
   </widget>
   <widget class="QTextEdit" name="te">
    <property name="geometry">
     <rect>
      <x>60</x>
      <y>100</y>
      <width>191</width>
      <height>311</height>
     </rect>
    </property>
   </widget>
  </widget>
  <widget class="QMenuBar" name="menubar">
   <property name="geometry">
    <rect>
     <x>0</x>
     <y>0</y>
     <width>323</width>
     <height>21</height>
    </rect>
   </property>
  </widget>
  <widget class="QStatusBar" name="statusbar"/>
 </widget>
 <resources/>
 <connections/>
</ui>

[day04.pyqt06]

import sys
from PyQt5 import uic
from PyQt5.QtWidgets import QApplication, QMainWindow

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

class MainClass(QMainWindow, form_class):
    def __init__(self) :
        QMainWindow.__init__(self)
        self.setupUi(self)
        self.pb.clicked.connect(self.myclick) # <widget class="QPushButton" name="pb">
        self.show()
        
    def myclick(self) :
        dan = self.sb.value()
        # print(type(dan))
        idan = int(dan)
        txt = ""
        for i in range(1, 9+1):
            # txt += str(dan)+"*"+str(i)+"="+str(idan*i)+"\n"
            txt += "{}*{}={}\n".format(dan, i, dan*i)
        self.te.setText(txt)
        
if __name__ == "__main__" :
    app = QApplication(sys.argv) 
    window = MainClass() 
    app.exec_()


[pyqt07.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>317</width>
    <height>281</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>MainWindow</string>
  </property>
  <widget class="QWidget" name="centralwidget">
   <widget class="QLabel" name="lblMine">
    <property name="geometry">
     <rect>
      <x>60</x>
      <y>50</y>
      <width>56</width>
      <height>12</height>
     </rect>
    </property>
    <property name="text">
     <string>나:</string>
    </property>
   </widget>
   <widget class="QLabel" name="lblCom">
    <property name="geometry">
     <rect>
      <x>60</x>
      <y>90</y>
      <width>56</width>
      <height>12</height>
     </rect>
    </property>
    <property name="text">
     <string>컴:</string>
    </property>
   </widget>
   <widget class="QLabel" name="lblResult">
    <property name="geometry">
     <rect>
      <x>60</x>
      <y>130</y>
      <width>56</width>
      <height>12</height>
     </rect>
    </property>
    <property name="text">
     <string>결과:</string>
    </property>
   </widget>
   <widget class="QLineEdit" name="leMine">
    <property name="geometry">
     <rect>
      <x>150</x>
      <y>40</y>
      <width>113</width>
      <height>20</height>
     </rect>
    </property>
   </widget>
   <widget class="QLineEdit" name="leCom">
    <property name="geometry">
     <rect>
      <x>150</x>
      <y>80</y>
      <width>113</width>
      <height>20</height>
     </rect>
    </property>
   </widget>
   <widget class="QLineEdit" name="leResult">
    <property name="geometry">
     <rect>
      <x>150</x>
      <y>120</y>
      <width>113</width>
      <height>20</height>
     </rect>
    </property>
   </widget>
   <widget class="QPushButton" name="pb">
    <property name="geometry">
     <rect>
      <x>60</x>
      <y>170</y>
      <width>201</width>
      <height>31</height>
     </rect>
    </property>
    <property name="text">
     <string>게임하기</string>
    </property>
   </widget>
  </widget>
  <widget class="QMenuBar" name="menubar">
   <property name="geometry">
    <rect>
     <x>0</x>
     <y>0</y>
     <width>317</width>
     <height>21</height>
    </rect>
   </property>
  </widget>
  <widget class="QStatusBar" name="statusbar"/>
 </widget>
 <resources/>
 <connections/>
</ui>

[day04.pyqt07]

import sys
from PyQt5 import uic
from PyQt5.QtWidgets import QApplication, QMainWindow
from random import random

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

class MainClass(QMainWindow, form_class):
    def __init__(self) :
        QMainWindow.__init__(self)
        self.setupUi(self)
        self.pb.clicked.connect(self.myclick) # <widget class="QPushButton" name="pb">
        self.leMine.returnPressed.connect(self.myclick)
        self.show()
        
    def myclick(self) :
        # pass
        mine = self.leMine.text()
        # print(mine)
        com = ""
        result = ""
        
        rnd = random()
        
        if rnd > 0.66:
            com = "가위"
        elif rnd > 0.33:
            com = "바위"
        else:
            com = "보"
            
        if com == "가위" and mine =="가위":
            result = "비김"
        if com == "가위" and mine =="바위":
            result = "이김"
        if com == "가위" and mine =="보":
            result = "짐"
            
        if com == "바위" and mine =="가위":
            result = "짐"
        if com == "바위" and mine =="바위":
            result = "비김"
        if com == "바위" and mine =="보":
            result = "이김"
            
        if com == "보" and mine =="가위":
            result = "이김"
        if com == "보" and mine =="바위":
            result = "짐"
        if com == "보" and mine =="보":
            result = "비김"
        
        self.leCom.setText(com)
        self.leResult.setText(result)
        
if __name__ == "__main__" :
    app = QApplication(sys.argv) 
    window = MainClass() 
    app.exec_()


[pyqt08.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>314</width>
    <height>620</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>MainWindow</string>
  </property>
  <widget class="QWidget" name="centralwidget">
   <widget class="QLabel" name="lbl_first">
    <property name="geometry">
     <rect>
      <x>60</x>
      <y>50</y>
      <width>56</width>
      <height>12</height>
     </rect>
    </property>
    <property name="text">
     <string>첫별수:</string>
    </property>
   </widget>
   <widget class="QLabel" name="lbl_last">
    <property name="geometry">
     <rect>
      <x>60</x>
      <y>110</y>
      <width>56</width>
      <height>12</height>
     </rect>
    </property>
    <property name="text">
     <string>끝별수:</string>
    </property>
   </widget>
   <widget class="QSpinBox" name="sb_first">
    <property name="geometry">
     <rect>
      <x>190</x>
      <y>40</y>
      <width>42</width>
      <height>22</height>
     </rect>
    </property>
    <property name="value">
     <number>1</number>
    </property>
   </widget>
   <widget class="QSpinBox" name="sb_last">
    <property name="geometry">
     <rect>
      <x>190</x>
      <y>100</y>
      <width>42</width>
      <height>22</height>
     </rect>
    </property>
    <property name="value">
     <number>3</number>
    </property>
   </widget>
   <widget class="QPushButton" name="pb">
    <property name="geometry">
     <rect>
      <x>60</x>
      <y>160</y>
      <width>171</width>
      <height>23</height>
     </rect>
    </property>
    <property name="text">
     <string>별출력하기</string>
    </property>
   </widget>
   <widget class="QPlainTextEdit" name="pte">
    <property name="geometry">
     <rect>
      <x>60</x>
      <y>220</y>
      <width>171</width>
      <height>301</height>
     </rect>
    </property>
   </widget>
  </widget>
  <widget class="QMenuBar" name="menubar">
   <property name="geometry">
    <rect>
     <x>0</x>
     <y>0</y>
     <width>314</width>
     <height>21</height>
    </rect>
   </property>
  </widget>
  <widget class="QStatusBar" name="statusbar"/>
 </widget>
 <resources/>
 <connections/>
</ui>

[day04.pyqt08]

import sys
from PyQt5 import uic
from PyQt5.QtWidgets import QApplication, QMainWindow
from random import random
from PyQt5.Qt import QPlainTextEdit

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

class MainClass(QMainWindow, form_class):
    def __init__(self) :
        QMainWindow.__init__(self)
        self.setupUi(self)
        self.pb.clicked.connect(self.myclick) # <widget class="QPushButton" name="pb">
        self.sb_first.valueChanged.connect(self.myclick)
        self.sb_last.valueChanged.connect(self.myclick)
        self.show()
        
    def getStar(self, cnt):
        ret = ""
        for i in range(0, cnt):
            ret += "★"
        return ret
        
    def myclick(self) :
        # pass
        f = self.sb_first.value()
        l = self.sb_last.value()
        
        txt = ""
        
        # txt += self.getStar(1) + "\n"
        # txt += self.getStar(2) + "\n"
        # print(txt)
        
        for i in range(f, l+1):
            txt += self.getStar(i) + "\n"
        
        self.pte.setPlainText(txt)
        
if __name__ == "__main__" :
    app = QApplication(sys.argv) 
    window = MainClass() 
    app.exec_()


[pyqt09.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>413</width>
    <height>444</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>60</x>
      <y>40</y>
      <width>291</width>
      <height>31</height>
     </rect>
    </property>
    <property name="alignment">
     <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
    </property>
   </widget>
   <widget class="QPushButton" name="pb1">
    <property name="geometry">
     <rect>
      <x>60</x>
      <y>110</y>
      <width>71</width>
      <height>31</height>
     </rect>
    </property>
    <property name="text">
     <string>1</string>
    </property>
   </widget>
   <widget class="QPushButton" name="pb2">
    <property name="geometry">
     <rect>
      <x>170</x>
      <y>110</y>
      <width>71</width>
      <height>31</height>
     </rect>
    </property>
    <property name="text">
     <string>2</string>
    </property>
   </widget>
   <widget class="QPushButton" name="pb3">
    <property name="geometry">
     <rect>
      <x>280</x>
      <y>110</y>
      <width>71</width>
      <height>31</height>
     </rect>
    </property>
    <property name="text">
     <string>3</string>
    </property>
   </widget>
   <widget class="QPushButton" name="pb4">
    <property name="geometry">
     <rect>
      <x>60</x>
      <y>180</y>
      <width>71</width>
      <height>31</height>
     </rect>
    </property>
    <property name="text">
     <string>4</string>
    </property>
   </widget>
   <widget class="QPushButton" name="pb5">
    <property name="geometry">
     <rect>
      <x>170</x>
      <y>180</y>
      <width>71</width>
      <height>31</height>
     </rect>
    </property>
    <property name="text">
     <string>5</string>
    </property>
   </widget>
   <widget class="QPushButton" name="pb6">
    <property name="geometry">
     <rect>
      <x>280</x>
      <y>180</y>
      <width>71</width>
      <height>31</height>
     </rect>
    </property>
    <property name="text">
     <string>6</string>
    </property>
   </widget>
   <widget class="QPushButton" name="pb7">
    <property name="geometry">
     <rect>
      <x>60</x>
      <y>250</y>
      <width>71</width>
      <height>31</height>
     </rect>
    </property>
    <property name="text">
     <string>7</string>
    </property>
   </widget>
   <widget class="QPushButton" name="pb8">
    <property name="geometry">
     <rect>
      <x>170</x>
      <y>250</y>
      <width>71</width>
      <height>31</height>
     </rect>
    </property>
    <property name="text">
     <string>8</string>
    </property>
   </widget>
   <widget class="QPushButton" name="pb9">
    <property name="geometry">
     <rect>
      <x>280</x>
      <y>250</y>
      <width>71</width>
      <height>31</height>
     </rect>
    </property>
    <property name="text">
     <string>9</string>
    </property>
   </widget>
   <widget class="QPushButton" name="pb0">
    <property name="geometry">
     <rect>
      <x>60</x>
      <y>320</y>
      <width>71</width>
      <height>31</height>
     </rect>
    </property>
    <property name="text">
     <string>0</string>
    </property>
   </widget>
   <widget class="QPushButton" name="pbCall">
    <property name="geometry">
     <rect>
      <x>170</x>
      <y>320</y>
      <width>181</width>
      <height>31</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>413</width>
     <height>21</height>
    </rect>
   </property>
  </widget>
  <widget class="QStatusBar" name="statusbar"/>
 </widget>
 <resources/>
 <connections/>
</ui>

[day04.pyqt09]

import sys
from PyQt5 import uic
from PyQt5.QtWidgets import QApplication, QMainWindow
from random import random
from PyQt5.Qt import QPlainTextEdit, QMessageBox

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

class MainClass(QMainWindow, form_class):
    def __init__(self) :
        QMainWindow.__init__(self)
        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)
        self.show()
        
    def myclick(self) :
        # pass
        # print(self.sender().text())
        str_new = self.sender().text()
        str_old = self.le.text()
        # print(str_new, str_old)
        self.le.setText(str_old + str_new)
        
    def mycall(self):
        str_tel = self.le.text()
        QMessageBox.about(self,'Calling',str_tel)
        
if __name__ == "__main__" :
    app = QApplication(sys.argv) 
    window = MainClass() 
    app.exec_()


* 오목 (10 * 10)

[day05.myomok01]

import sys
from PyQt5 import uic
from PyQt5.QtWidgets import QApplication, QMainWindow, QLabel, QGridLayout, QWidget
from PyQt5.QtGui import QPixmap

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

class MainClass(QMainWindow, form_class):
    def __init__(self):
        QMainWindow.__init__(self)
        self.setupUi(self)
        self.show()

        central_widget = QWidget()
        self.setCentralWidget(central_widget)

        grid_layout = QGridLayout(central_widget)

        image_path = "0.png"

        for row in range(10):
            for col in range(10):
                image_label = QLabel(self)

                pixmap = QPixmap(image_path)
                image_label.setPixmap(pixmap)

                image_label.setMargin(0)

                grid_layout.addWidget(image_label, row, col)

if __name__ == "__main__":
    app = QApplication(sys.argv)
    window = MainClass()
    app.exec_()

'대덕인재개발원 > 대덕인재개발원_파이썬 프로그래밍' 카테고리의 다른 글

231106_파이썬 기초 8  (0) 2023.11.06
231103_파이썬 기초 7  (0) 2023.11.03
231101_파이썬 기초 5  (0) 2023.11.01
231031_파이썬 기초 4  (0) 2023.10.31
231030_파이썬 기초 3  (0) 2023.10.30