gpt4 book ai didi

python - 让 PySide Hello 应用程序在 Canopy 下运行

转载 作者:行者123 更新时间:2023-11-30 23:16:56 29 4
gpt4 key购买 nike

一位 Canopy 用户在这里学习 PySide。当我运行下面的演示代码时,QApplication 提示事件循环已经在运行。'

import sys
from PySide.QtCore import *
from PySide.QtGui import *


# Create a Qt application
#app = QApplication(sys.argv) #QApplication complains an instance already exists
app = QApplication.instance() #So we just ask for the instance.

#app.aboutToQuit.connect(app.deleteLater)
# Create a Label and show it
label = QLabel("Hello World")
label.show()
# Enter Qt application main loop
app.exec_()
sys.exit()

那么我怎样才能运行这个简单的代码呢?

最佳答案

是的,Pylab 是 IPython 的一种模式,它为 IPython 前端启动事件循环,以便您可以在 IPython 命令行与 GUI 进行交互。

这是一个简单的代码示例,无论有没有 Pylab,都可以运行。

import sys
from PySide import QtGui
app = QtGui.QApplication.instance()
standalone = app is None
if standalone:
app = QtGui.QApplication(sys.argv)
wid = QtGui.QWidget()
wid.resize(250,150)
wid.setWindowTitle('Simple')
wid.show()
if standalone:
sys.exit(app.exec_())
else:
print "We're back with the Qt window still active"

关于python - 让 PySide Hello 应用程序在 Canopy 下运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27536518/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com