python-pyqt4的主窗口界面程序显示问题,谢谢各位了

qq_40168296 2017-11-15 03:24:37
系统运行没有报错,我仿照的程序我看各个环节都有,但是运行之后就是不显示窗口,主函数也有。程序如下,请各位指点迷津谢谢了
from PyQt4.Qt import *
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import time
import OpenOPC
import sys
from PyQt4 import QtGui
from PyQt4 import QtCore
class Test(QtGui.QMainWindow):
def __init__(self):
super(Test, self).__init__()
self.UI()
self.opc = OpenOPC.client()
self.opc.connect('matrikon.opc.simulation.1')
def UI(self):
self.but1= QPushButton('start')
self.but2=QPushButton('settings')
self.but3=QPushButton('close')
self.but1.clicked.connect(self.set)
self.but2.clicked.connect(self.read)
self.but3.clicked(exit())
self.setGeometry(500,500,250,250)
self.but1.move(100,100)
self.but2.move(200,100)
self.but3.move(300,100)
self.setWindowTitle('opc mainwindow')
self.show()
def set(self):
self.setGeometry(500,500,250,250)
self.setWindowTitle('settings')
self.but4=QPushButton('frequency')
self.but5=QPushButton('addition')
self.frequency.clicked.connect(self.showdialog)
self.line1 = QtGui.QLineEdit(self)
self.addition.clicked(self.add)
self.but6=QPushButton('read')
self.but6.clicked(self.read)
def showdialog(self):
text, ok = QtGui.QInputDialog.getText(self, 'Input Dialog', 'Enter the frenquency:')
if ok:
self.line1.setText(str(text))
def add(self):#show the opc list
self.line2 = QtGui.QLineEdit(self)
self.line2.move(100,100)
self.line2=self.opc.list()
self.line3=QtGui.QLineEdit(self)
self.line3.move(200,100)
self.but5=QPushButton('add')
self.but5.clicked(self.show)
def show(self):
text, ok = QtGui.QInputDialog.getText(self, 'Input Dialog', 'Enter the type you want')
if ok:
self.line3.setText(str(text))
def read(self):
while True:
self.opc.time.sleep(self.line1)
self.opc.read('self.line3')
def main():
app = QtGui.QApplication(sys.argv)
ex = Test()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
...全文
348 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq_40168296 2017-11-15
  • 打赏
  • 举报
回复
ok,成了,虽然出现了很多bug 我可以好好修改了,谢谢了】
手无护鸡之力 2017-11-15
  • 打赏
  • 举报
回复
self.but3.clicked(exit()) 改成 self.but3.clicked.connect(self.close)
qq_40168296 2017-11-15
  • 打赏
  • 举报
回复
您好,加了ex.show()了还是没反应,还是冒昧再次请教了。 from PyQt4.Qt import * from PyQt4.QtCore import * from PyQt4.QtGui import * import time import OpenOPC import sys from PyQt4 import QtGui from PyQt4 import QtCore class Test(QtGui.QMainWindow): def __init__(self): super(Test, self).__init__() self.UI() self.opc = OpenOPC.client() self.opc.connect('matrikon.opc.simulation.1') def UI(self): self.but1= QPushButton('start') self.but2=QPushButton('settings') self.but3=QPushButton('close') self.but1.clicked.connect(self.set) self.but2.clicked.connect(self.read) self.but3.clicked(exit()) self.setGeometry(500,500,250,250) self.but1.move(100,100) self.but2.move(200,100) self.but3.move(300,100) self.setWindowTitle('opc mainwindow') self.show() def set(self): self.setGeometry(500,500,250,250) self.setWindowTitle('settings') self.but4=QPushButton('frequency') self.but5=QPushButton('addition') self.frequency.clicked.connect(self.showdialog) self.line1 = QtGui.QLineEdit(self) self.addition.clicked(self.add) self.but6=QPushButton('read') self.but6.clicked(self.read) def showdialog(self): text, ok = QtGui.QInputDialog.getText(self, 'Input Dialog', 'Enter the frenquency:') if ok: self.line1.setText(str(text)) def add(self):#show the opc list self.line2 = QtGui.QLineEdit(self) self.line2.move(100,100) self.line2=self.opc.list() self.line3=QtGui.QLineEdit(self) self.line3.move(200,100) self.but5=QPushButton('add') self.but5.clicked(self.show) def show(self): text, ok = QtGui.QInputDialog.getText(self, 'Input Dialog', 'Enter the type you want') if ok: self.line3.setText(str(text)) def read(self): while True: self.opc.time.sleep(self.line1) self.opc.read('self.line3') def main(): app = QtGui.QApplication(sys.argv) ex = Test() ex.show() sys.exit(app.exec_()) if __name__ == '__main__': main()
手无护鸡之力 2017-11-15
  • 打赏
  • 举报
回复
ex.show()

37,720

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧