반응형

/*********************************************************************************************************
-- Title : [PyQt4] Calendar Widget 구현

-- Reference : pythonspot.com
-- Key word : 파이썬 python pyqt qt qt4 gui 달력 칼렌터 칼렌다 calendar

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

# -*- 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.
w = QWidget() # The QWidget widget is the base class
w.setWindowTitle('Add Calendar Widget')
w.resize(400, 350)

# ------------------------------------------
# -- Create textbox
# ------------------------------------------
myTextbox = QLineEdit(w)
myTextbox.move(20, 20)
myTextbox.resize(360,40)

# ------------------------------------------
# -- Create calendar widget
# ------------------------------------------
cal = QCalendarWidget(w)
cal.setGridVisible(True)
cal.move(20, 80)
cal.resize(320,240)

# ------------------------------------------
# -- Create the actions
# ------------------------------------------
@pyqtSlot()
def on_select():
date = cal.selectedDate()

myTextbox.setText(date.toString())

print date
print date.day(), date.month(), date.year()

# ------------------------------------------
# -- Connect the signals to the slots
# ------------------------------------------
cal.clicked.connect(on_select)

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



반응형

+ Recent posts