๋ชฉ์ฐจ
import sys
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
class Main(QDialog):
def __init__(self):
super().__init__()
self.init_ui()
def init_ui(self):
main_layout = QVBoxLayout()
self.setLayout(main_layout)
self.resize(500,500)
self.show()
if __name__ =='__main__':
app = QApplication(sys.argv)
main = Main()
sys.exit(app.exec_()
์์ ฏ ์ถ๊ฐ
import sys
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
class Main(QDialog):
def __init__(self):
super().__init__()
self.init_ui()
def init_ui(self):
main_layout = QVBoxLayout()
#vertical box layout ์ด๋ผ์ add์์ผ์ค ์์๋๋ก ์์์ ์๋๋ก ๋ด๊ธด๋ค. -> ์์ ฏ์ ์์ง์ผ๋ก ๋ฐฐ์น
#horizontal๋ก ํด์ฃผ๋ ค๋ฉด V๋ฅผ H๋ก ๋ฐ๊ฟ์ฃผ๋ฉด ๋๋ค. -> ๊ฐ๋ก๋ฐฉํฅ ๋ฐฐ์น
w_1 = QPushButton("widget_1")
w_2 = QPushButton("widget_2")
w_3 = QPushButton("widget_3")
main_layout.addWidget(w_1)
main_layout.addWidget(w_2)
main_layout.addWidget(w_3)
self.setLayout(main_layout)
sel
ํ๋ฉด์ ๋๋ถ๋ถ 2์ฐจ์
w_1 = QPushButton("widget_1")
w_2 = QPushButton("widget_2")
w_3 = QPushButton("widget_3")
w_4 = QPushButton("widget_4")
main_layout.addWidget(w_1, 0, 0) #ํ ์ฑ๋ถ๊ณผ ์ด ์ฑ๋ถ์ ์ ์ด์ค๋ค.
main_layout.addWidget(w_2, 0, 1)
main_layout.addWidget(w_3, 1, 0)
main_layout.addWidget(w_4, 1, 1)
QGridLayout์ 2์ฐจ์ ๋ฐฐ์น์ด๋ค.
4๊ฐ๋ฅผ 2*2 ํ๋ ฌ์ฒ๋ผ ๋ฐฐ์น
ํผํฉ
import sys
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
class Main(QDialog):
def __init__(self):
super().__init__()
self.init_ui()
def init_ui(self):
main_layout =QVBoxLayout()
#vertical box layout ์ด๋ผ์ add์์ผ์ค ์์๋๋ก ์์์ ์๋๋ก ๋ด๊ธด๋ค. -> ์์ ฏ์ ์์ง์ผ๋ก ๋ฐฐ์น
#horizontal๋ก ํด์ฃผ๋ ค๋ฉด V๋ฅผ H๋ก ๋ฐ๊ฟ์ฃผ๋ฉด ๋๋ค. -> ๊ฐ๋ก๋ฐฉํฅ ๋ฐฐ์น
w_1 = QPushButton("widget_1")
w_2 = QPushButton("widget_2")
w_3 = QPushButton("widget_3")
w_4 = QPushButton("widget_4")
w_5 = QPushButton("widget_5")
layout_1 = QHBoxLayout()
layout_2 = QHBoxLayout()
layout_1.addWidget(w_1)
layout_1.addWidget(w_2)
layout_2.addWidget(w_4)
layout_2.addWidget(w_5)
main_layout.addLayout(layout_1)
main_layout.addWidget(w_3)
main_layout.addLayout(layout_2)
self.setLayout(main_layout)
self.resize(500,500)
self.show()
if __name__ =='__main__':
app = QApplication(sys.argv)
main = Main()
sys.exit(app.exec_())
์กฐ๊ธ ๋ ๋ณต์กํ ๋ฐฐ์น๋ฅผ ํด๋ณด์
import sys
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
class Main(QDialog):
def __init__(self):
super().__init__()
self.init_ui()
def init_ui(self):
main_layout =QHBoxLayout()
#vertical box layout ์ด๋ผ์ add์์ผ์ค ์์๋๋ก ์์์ ์๋๋ก ๋ด๊ธด๋ค. -> ์์ ฏ์ ์์ง์ผ๋ก ๋ฐฐ์น
#horizontal๋ก ํด์ฃผ๋ ค๋ฉด V๋ฅผ H๋ก ๋ฐ๊ฟ์ฃผ๋ฉด ๋๋ค. -> ๊ฐ๋ก๋ฐฉํฅ ๋ฐฐ์น
w_1 = QPushButton("widget_1")
w_2 = QPushButton("widget_2")
w_3 = QPushButton("widget_3")
w_4 = QPushButton("widget_4")
w_5 = QPushButton("widget_5")
#๊ฐ์ฅ ์์ ๋ ์ด์์๋ถํฐ ๋ง๋๋ ๊ฒ์ด ํธํ๋ค
layout_3 = QVBoxLayout()
layout_3.addWidget(w_4)
layout_3.addWidget(w_5)
layout_2=QHBoxLayout()
layout_2.addWidget(w_3)
layout_2.addLayout(layout_3)
layout_1 = QVBoxLayout()
layout_1.addWidget(w_2)
layout_1.addLayout(layout_2)
main_layout.addWidget(w_1)
main_layout.addLayout(layout_1)
self.setLayout(main_layout)
self.resize(500,500)
self.show()
if __name__ =='__main__':
app = QApplication(sys.argv)
main = Main()
sys.exit(app.exec_())
๋ ํด๋ณด์~
import sys
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
class Main(QDialog):
def __init__(self):
super().__init__()
self.init_ui()
def init_ui(self):
main_layout =QVBoxLayout()
#vertical box layout ์ด๋ผ์ add์์ผ์ค ์์๋๋ก ์์์ ์๋๋ก ๋ด๊ธด๋ค. -> ์์ ฏ์ ์์ง์ผ๋ก ๋ฐฐ์น
#horizontal๋ก ํด์ฃผ๋ ค๋ฉด V๋ฅผ H๋ก ๋ฐ๊ฟ์ฃผ๋ฉด ๋๋ค. -> ๊ฐ๋ก๋ฐฉํฅ ๋ฐฐ์น
w_1 = QPushButton("widget_1")
w_2 = QPushButton("widget_2")
w_3 = QPushButton("widget_3")
w_4 = QPushButton("widget_4")
w_5 = QPushButton("widget_5")
w_6 = QPushButton("widget_6")
w_7 = QPushButton("widget_7")
w_8 = QPushButton("widget_8")
w_9 = QPushButton("widget_9")
w_10 = QPushButton("widget_10")
w_11 = QPushButton("widget_11")
layout_attacker = QHBoxLayout()
layout_midfielder = QHBoxLayout()
layout_defender = QHBoxLayout()
layout_attacker.addWidget(w_1)
layout_attacker.addWidget(w_2)
layout_attacker.addWidget(w_3)
layout_midfielder.addWidget(w_4)
layout_midfielder.addWidget(w_5)
layout_midfielder.addWidget(w_6)
layout_defender.addWidget(w_7)
layout_defender.addWidget(w_8)
layout_defender.addWidget(w_9)
layout_defender.addWidget(w_10)
main_layout.addLayout(layout_attacker)
main_layout.addLayout(layout_midfielder)
main_layout.addLayout(layout_defender)
main_layout.addWidget(w_11)
self.setLayout(main_layout)
self.resize(500,500)
self.show()
if __name__ =='__main__':
app = QApplication(sys.argv)
main = Main()
sys.exit(app.exec_())
728x90
'2022 > ์คํ์์ค ์ํํธ์จ์ด ํ๋ก์ ํธ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
QGridLayout (0) | 2022.11.23 |
---|---|
GUI ๊ฐ์ 5 (0) | 2022.11.23 |
GUI ๊ฐ์ 4 (0) | 2022.11.22 |
GUI ๊ฐ์3 (0) | 2022.11.21 |
GUI ๊ฐ์ 1 (0) | 2022.11.20 |