๋ชฉ์ฐจ
์ค๊ฐ๊ณผ์
mport sys
from PyQt5.QtWidgets import *
class Main(QDialog):
def __init__(self):
super().__init__()
self.init_ui()
def init_ui(self):
main_layout =QVBoxLayout()
## #๋ ์ด์์ ํ ์ก๊ธฐ ###
layout_operation_solution = QFormLayout()
layout_funct1 = QGridLayout()
layout_funct2 =QGridLayout()
### ์์ ์
๋ ฅ & ๊ฒฐ๊ณผ ๊ฐ ๋ํ๋๋ operation_solution ์ฐฝ ๊ตฌํ ###
self.operation_solution = QLineEdit()
layout_operation_solution.addRow("", self.operation_solution)
self.setLayout(main_layout)
self.resize(400, 400)
self.show()
### ๊ธฐ๋ฅ funct1 ๋ฒํผ ๊ตฌํ ###
###๋๋จธ์ง
self.remainder = QPushButton("%")
##CE
self.clear_entry = QPushButton("CE")
## C
self.clear = QPushButton("C")
self.backspace = QPushButton("์ง์ฐ๊ธฐ")
### 1/x
self.reciprocal =QPushButton("1/x")
### ์ ๊ณฑ
self.squre = QPushButton("์ ๊ณฑ")
### ์ ๊ณฑ๊ทผ
self.square_root=QPushButton("์ ๊ณฑ๊ทผ")
### ๋๋๊ธฐ
self.devision = QPushButton("÷")
layout_funct1.addWidget(self.remainder,0 , 0)
layout_funct1.addWidget(self.clear_entry,0 , 1)
layout_funct1.addWidget(self.clear,0 ,2)
layout_funct1.addWidget(self.backspace,0 ,3)
layout_funct1.addWidget(self.reciprocal,1 , 0)
layout_funct1.addWidget(self.squre,1,1)
layout_funct1.addWidget(self.square_root,1 ,2)
layout_funct1.addWidget(self.devision,1 , 3)
### layout_number ๊ตฌ์ฑํ๊ธฐ ###
self.button_production = QPushButton("x")
self.button_minus =QPushButton("-")
self.button_plus = QPushButton("+")
self.button_result = QPushButton("=")
self.button_plus_minus = QPushButton("+/-")
self.button_add_dot = QPushButton(".")
layout_funct2.addWidget(self.button_production,0,3)
layout_funct2.addWidget(self.button_minus,1,3)
layout_funct2.addWidget(self.button_plus,2,3)
layout_funct2.addWidget(self.button_result,3,3)
layout_funct2.addWidget(self.button_plus_minus,3,0)
layout_funct2.addWidget(self.button_add_dot,3,2)
number_button_dicct = {}
for number in range(0, 10):
number_button_dicct[number] = QPushButton(str(number))
number_button_dicct[number].clicked.connect(lambda state, num=number: self.number_button_click(num))
if number > 0:
x, y = divmod(number - 1, 3)
# 4์ผ๋ก ๋๋ด์ ๋ ๋ชซ๊ณผ ๋๋จธ์ง์ ๋ฐ๋ผ ๋ฐฐ์น๋ฅผ ํ๋ฉด ๋๋ค.
layout_funct2.addWidget(number_button_dicct[number], x, y)
elif number == 0:
layout_funct2.addWidget(number_button_dicct[number], 3, 1)
###main_layout์ ์ถ๊ฐ ###
main_layout.addLayout(layout_operation_solution)
main_layout.addLayout(layout_funct1)
main_layout.addLayout(layout_funct2)
if __name__ =='__main__':
app = QApplication(sys.argv)
main = Main()
sys.exit(app.exec_())
import sys
from PyQt5.QtWidgets import *
class Main(QDialog):
def __init__(self):
super().__init__()
self.init_ui()
def init_ui(self):
main_layout =QVBoxLayout()
## #๋ ์ด์์ ํ ์ก๊ธฐ ###
layout_operation_solution = QFormLayout()
layout_funct1 = QGridLayout()
layout_funct2 =QGridLayout()
### ์์ ์
๋ ฅ & ๊ฒฐ๊ณผ ๊ฐ ๋ํ๋๋ operation_solution ์ฐฝ ๊ตฌํ ###
self.operation_solution = QLineEdit()
layout_operation_solution.addRow("", self.operation_solution)
self.setLayout(main_layout)
self.resize(400, 400)
self.show()
### ๊ธฐ๋ฅ funct1 ๋ฒํผ ๊ตฌํ ###
###๋๋จธ์ง
self.remainder = QPushButton("%")
##CE
self.clear_entry = QPushButton("CE")
## C
self.clear = QPushButton("C")
self.backspace = QPushButton("์ง์ฐ๊ธฐ")
### 1/x
self.reciprocal =QPushButton("1/x")
### ์ ๊ณฑ
self.squre = QPushButton("์ ๊ณฑ")
### ์ ๊ณฑ๊ทผ
self.square_root=QPushButton("์ ๊ณฑ๊ทผ")
### ๋๋๊ธฐ
self.devision = QPushButton("÷")
layout_funct1.addWidget(self.remainder,0 , 0)
layout_funct1.addWidget(self.clear_entry,0 , 1)
layout_funct1.addWidget(self.clear,0 ,2)
layout_funct1.addWidget(self.backspace,0 ,3)
layout_funct1.addWidget(self.reciprocal,1 , 0)
layout_funct1.addWidget(self.squre,1,1)
layout_funct1.addWidget(self.square_root,1 ,2)
layout_funct1.addWidget(self.devision,1 , 3)
### layout_number ๊ตฌ์ฑํ๊ธฐ ###
self.button_production = QPushButton("x")
self.button_minus =QPushButton("-")
self.button_plus = QPushButton("+")
self.button_result = QPushButton("=")
self.button_plus_minus = QPushButton("+/-")
self.button_add_dot = QPushButton(".")
layout_funct2.addWidget(self.button_production,0,3)
layout_funct2.addWidget(self.button_minus,1,3)
layout_funct2.addWidget(self.button_plus,2,3)
layout_funct2.addWidget(self.button_result,3,3)
layout_funct2.addWidget(self.button_plus_minus,3,0)
layout_funct2.addWidget(self.button_add_dot,3,2)
number_button_dicct = {}
for number in range(0, 10):
number_button_dicct[number] = QPushButton(str(number))
if number > 0:
x, y = divmod(number - 1, 3)
# 3์ผ๋ก ๋๋ด์ ๋ ๋ชซ๊ณผ ๋๋จธ์ง์ ๋ฐ๋ผ ๋ฐฐ์น๋ฅผ ํ๋ฉด ๋๋ค.
if x==0:
layout_funct2.addWidget(number_button_dicct[number], 2, y)
elif x==2:
layout_funct2.addWidget(number_button_dicct[number], 0, y)
else:
layout_funct2.addWidget(number_button_dicct[number], x, y)
elif number == 0:
layout_funct2.addWidget(number_button_dicct[number], 3, 1)
###main_layout์ ์ถ๊ฐ ###
main_layout.addLayout(layout_operation_solution)
main_layout.addLayout(layout_funct1)
main_layout.addLayout(layout_funct2)
if __name__ =='__main__':
app = QApplication(sys.argv)
main = Main()
sys.exit(app.exec_())
LineEdit()๊ฐ ์๋ ์ ์ ๋ ฅ์ฐฝ ํฌ๊ธฐ ํค์ฐ๊ธฐ
self.operation_solution.setSizePolicy(QSizePolicy.Expanding,QSizePolicy.Expanding)
์ ๋ ฅ๋ ์ผ์ชฝ๋ถํฐ ๋๋๋ก ํด์ผํ๋์?
728x90
'2022 > ์คํ์์ค ์ํํธ์จ์ด ํ๋ก์ ํธ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
. ๋ฒํผ ๊ธฐ๋ฅ ์ถ๊ฐ ์์ (0) | 2022.11.27 |
---|---|
float๊ฐ ์ ์์ธ์ง ํ์ธํ๊ธฐ (0) | 2022.11.27 |
QGridLayout (0) | 2022.11.23 |
GUI ๊ฐ์ 5 (0) | 2022.11.23 |
GUI ๊ฐ์ 4 (0) | 2022.11.22 |