#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
from PyQt4 import QtGui
global username
username = " "
class Home(QtGui.QWidget):
def __init__(self):
super(Home, self).__init__()
self.initUI()
def initUI(self):
font = QtGui.QFont("Arial",10,QtGui.QFont.Bold,False)
username = QtGui.QLabel('Username',self)
username.move(10,40)
username.setFont(font);
usernameEdit = QtGui.QLineEdit(self)
usernameEdit.move(100,35)
usernameEdit.textChanged[str].connect(self.onChangedusername)
usernameEdit.setFocus()
btn = QtGui.QPushButton('Login', self)
btn.move(10, 80)
btn.setFixedWidth(130)
btn.setFixedHeight(50)
btn.setStyleSheet("background-color: #FF0000") #red color
btn.clicked.connect(self.begin)
btn.setFont(font)
self.setGeometry(5, 30, 600, 300)
self.setWindowTitle('CSCI237') #Update window title to CSCI237
self.show()
def onChangedusername(self, text):
global username
username = str(text)
def begin(self):
print username
def main():
app = QtGui.QApplication(sys.argv)
ex = Home()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
- 将窗口标题更新为 CSCI237 - 课程注册
- 更改登录按钮颜色。提示:使用十六进制颜色代码
- 更新代码以在单击登录按钮时打印“Hello –username-”。
- 添加一个名为 Logout 的新按钮,单击该按钮会打印“再见”。