반응형

/*********************************************************************************************************
-- Title : [PyQt4] Tab 구현

-- Reference : pythonspot.com
-- Key word : 파이썬 python pyqt qt qt4 gui 탭 tab

*********************************************************************************************************/

# -*- coding: utf-8 -*-

import sys
from PyQt4.QtCore import pyqtSlot
from PyQt4.QtGui import *

# ------------------------------------------
# -- Create window
# ------------------------------------------
myApp = QApplication(sys.argv) # Create an PyQT4 application object.
tabs = QTabWidget()
tabs.setWindowTitle('Create Tabs')
tabs.resize(300, 200)

# ------------------------------------------
# Create tabs
# ------------------------------------------
tab1 = QWidget()
tab2 = QWidget()
tab3 = QWidget()
tab4 = QWidget()

# Add tabs
tabs.addTab(tab1, "Tab-1")
tabs.addTab(tab2, "Tab-2")
tabs.addTab(tab3, "Tab-3")
tabs.addTab(tab4, "Tab-4")

# ------------------------------------------
# -- Set layout of Tab-1
# ------------------------------------------
vBoxlayout = QVBoxLayout()
myTextbox = QLineEdit()
pushButton1 = QPushButton("Start")
pushButton2 = QPushButton("Settings")
pushButton3 = QPushButton("Stop")

vBoxlayout.addWidget(myTextbox)
vBoxlayout.addWidget(pushButton1)
vBoxlayout.addWidget(pushButton2)
vBoxlayout.addWidget(pushButton3)

tab1.setLayout(vBoxlayout)

# ------------------------------------------
# -- Create the actions
# ------------------------------------------
@pyqtSlot()
def on_button1():
myTextbox.setText("Clicked Start!")

@pyqtSlot()
def on_button2():
myTextbox.setText("Clicked Settings!")

@pyqtSlot()
def on_button3():
myTextbox.setText("Clicked Stop!")

# ------------------------------------------
# -- Connect the signals to the slots
# ------------------------------------------
pushButton1.clicked.connect(on_button1)
pushButton2.clicked.connect(on_button2)
pushButton3.clicked.connect(on_button3)

# ------------------------------------------
# -- Show the window and run the app
# ------------------------------------------
tabs.show()
myApp.exec_()




반응형

+ Recent posts