def enter_ex2(self): "Enter experiment 2" self.ex2 = ExofComp(self.__resultFolder) self.ex2.show()
class Window(QtGui.QWidget): # inherit def __init__(self, username): super(Window, self).__init__() self.__resultFolder = os.path.join('result', username) if not os.path.isdir('result'): os.mkdir('result') if not os.path.isdir(self.__resultFolder): os.mkdir(self.__resultFolder) self.initUI() def initUI(self): self.setWindowTitle('Learn PyQt') self.resize(350, 250) self.center() self.setWindowIcon(QtGui.QIcon('icons/idle.ico')) #set buttons btn_ex1 = QtGui.QPushButton(_fromUtf8("进入实验1"), self) #btn_ex1.move(50,50) btn_ex2 = QtGui.QPushButton(_fromUtf8(("进入实验2")), self) #btn_ex2.move(200,50) #connect buttons self.connect(btn_ex1, QtCore.SIGNAL('clicked()'), self.enter_ex1) self.connect(btn_ex2, QtCore.SIGNAL('clicked()'), self.enter_ex2) grid = QtGui.QGridLayout() self.setLayout(grid) label1 = QtGui.QLabel(self) label2 = QtGui.QLabel(self) label1.setText(_fromUtf8("实验1:空气质量分类\n" \ + "1.将给出一张图片,根据这张图片判断空气质量等级。\n" \ + "2.空气质量等级将分为6级,1级代表最好,6级代表最差。\n" \ + "3.选择图片下方相应的按钮进行评价。")) label2.setText(_fromUtf8(("实验2:空气质量比较\n" \ + "1.将给出两张图片,根据这两张图片,给出自己的判断。\n" \ + "2.给出认为空气质量较好的那张图片\n" \ + "3.点击对应图片下方的按钮做出选择"))) grid.addWidget(label1, 0, 0) grid.addWidget(label2, 0, 1) grid.addWidget(btn_ex1, 1, 0) grid.addWidget(btn_ex2, 1, 1) # set statusbar #self.statusBar().showMessage('Ready') def center(self): "move to center of screen" # get the size of screen screen = QtGui.QDesktopWidget().screenGeometry() #self size size = self.geometry() self.move((screen.width() - size.width()) / 2, (screen.height() - size.height()) / 2) def enter_ex1(self): "Enter experiment 1 " self.extra = Extra() self.extra.show() self.extra.exec_() self.ex1 = ExofClass(self.__resultFolder) self.ex1.show() def enter_ex2(self): "Enter experiment 2" self.ex2 = ExofComp(self.__resultFolder) self.ex2.show()