我是Qt Creator的新手。我正在学习为Python开发GUI。
当我像“导入PyQt4”那样导入PyQt4模块时,出现错误: “ AttributeError:'模块'对象没有属性'uic'”,但其余模块(例如QtGui)可以正常工作。
但是如果我使用“ import PyQt4.uic”或“ from PyQt4 import uic”,则uic可以正常工作。
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Convierte temperaturas
# www.pythondiario.com
import sys, os
import PyQt4
# Cargar nuestro archivo .ui
form_class = PyQt4.uic.loadUiType("tempconv.ui")[0]
class MyWindowClass(PyQt4.QtGui.QMainWindow, form_class):
def __init__(self, parent=None):
PyQt4.QtGui.QMainWindow.__init__(self, parent)
self.setupUi(self)
self.btn_CtoF.clicked.connect(self.btn_CtoF_clicked)
self.btn_FtoC.clicked.connect(self.btn_FtoC_clicked)
self.change_image_button_1.clicked.connect(self.change_image_button_clicked_1)
self.change_image_button_2.clicked.connect(self.change_image_button_clicked_2)
# Evento del boton btn_CtoF
def btn_CtoF_clicked(self):
cel = float(self.editCel.text())
fahr = cel * 9 / 5.0 + 32
self.spinFahr.setValue(int(fahr + 0.5))
# Evento del boton btn_FtoC
def btn_FtoC_clicked(self):
fahr = self.spinFahr.value()
cel = ((fahr - 32) * 5) / 9
self.editCel.setText(str(cel))
def change_image_button_clicked_1(self):
#self.lbl= QtGui.QLabel(label_3)
self.label_3.setPixmap(PyQt4.QtGui.QPixmap("Logos/Logo_Lean_Manufacturing_UVa.jpg"))
self.label_3.show
def change_image_button_clicked_2(self):
#self.lbl= QtGui.QLabel(label_3)
self.label_3.setPixmap(PyQt4.QtGui.QPixmap("Logos/Logo_EII.jpg"))
self.label_3.show
app = PyQt4.QtGui.QApplication(sys.argv)
MyWindow = MyWindowClass(None)
MyWindow.show()
app.exec_()
有人知道为什么会这样吗?