pyqt:messagebox几秒钟后自动关闭(pyqt: messagebox automatically closing after few seconds)
我正在尝试做一个警告消息框,几秒后会自动消失。 我做了这个代码:
def warning(self): messagebox = QtGui.QMessageBox(self) messagebox.setWindowTitle("wait") messagebox.setText("wait (closing automatically in {0} secondes.)".format(3)) messagebox.setStandardButtons(messagebox.NoButton) self.timer2 = QtCore.QTimer() self.time_to_wait = 3 def close_messagebox(e): e.accept() self.timer2.stop() self.time_to_wait = 3 def decompte(): messagebox.setText("wait (closing automatically in {0} secondes.)".format(self.time_to_wait)) if self.time_to_wait <= 0: messagebox.closeEvent = close_messagebox messagebox.close() self.time_to_wait -= 1 self.connect(self.timer2,QtCore.SIGNAL("timeout()"),decompte) self.timer2.start(1000) messagebox.exec_()
对于自动关闭部件,它实际上工作正常。 我的问题是,当有人试图在几秒钟之前手动关闭它,通过单击窗口的x按钮,消息框永远不会关闭。 “等待时间”变为否定,消息框显示“例如-4秒自动关闭”,它将永远不会关闭。
知道如何避免这种情况吗? 问候
I am trying to do a warning message box that disappears automatically after few seconds. I have done this code:
def warning(self): messagebox = QtGui.QMessageBox(self) messagebox.setWindowTitle("wait") messagebox.setText("wait (closing automatically in {0} secondes.)".format(3)) messagebox.setStandardButtons(messagebox.NoButton) self.timer2 = QtCore.QTimer() self.time_to_wait = 3 def close_messagebox(e): e.accept() self.timer2.stop() self.time_to_wait = 3 def decompte(): messagebox.setText("wait (closing automatically in {0} secondes.)".format(self.time_to_wait)) if self.time_to_wait <= 0: messagebox.closeEvent = close_messagebox messagebox.close() self.time_to_wait -= 1 self.connect(self.timer2,QtCore.SIGNAL("timeout()"),decompte) self.timer2.start(1000) messagebox.exec_()
It works actually fine, for the automatic closing part. My problem is that when someone try to close it manually before the few seconds, by clicking on the x button of the window, the message box never closes. the "time to wait" goes negative, the message box shows "closing automatically in -4 seconds" for example, and it will never close.
Any idea how I could avoid that ? Regards
原文:https://stackoverflow.com/questions/40932639
最满意答案
64位java不在“Program Files(x86)”中,因为“Program Files(x86)”用于32位程序。 尝试查看“程序文件”。
64 bit java isn't in "Program Files(x86)" because "Program Files(x86)" is for 32 bit programs. Try looking in "Program Files" instead.
相关问答
更多-
您需要正确设置路径才能运行java二进制文件。 从用于Microsoft Windows的JDK安装 : Updating the PATH Environment Variable If you do not set the PATH variable, you need to specify the full path to the executable file every time you run it, such as: C:\> "C:\Program Files\Java\jdk1.8.0 ...
-
是否可以在Windows 7上安装32位和64位Java?(Is it possible to install both 32bit and 64bit Java on Windows 7?)[2024-02-07]
是的,这绝对没有问题。 您甚至可以在同一台机器上同时安装32位和64位Java的多个版本。 其实我自己有这样的设置。 Yes, it is absolutely no problem. You could even have multiple versions of both 32bit and 64bit Java installed at the same time on the same machine. In fact, i have such a setup myself. -
使用Python 2.7.3在64位Windows 7上安装Numpy [已关闭](Installing Numpy on 64bit Windows 7 with Python 2.7.3 [closed])[2023-04-20]
尝试本网站的(非官方)二进制文件: http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy 您可以获得最新的numpy x64,包括或不使用用于Python 2.7或Python 3的Intel MKL库。 Try the (unofficial) binaries in this site: http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy You can get the newest numpy x64 with ... -
64位java不在“Program Files(x86)”中,因为“Program Files(x86)”用于32位程序。 尝试查看“程序文件”。 64 bit java isn't in "Program Files(x86)" because "Program Files(x86)" is for 32 bit programs. Try looking in "Program Files" instead.
-
java -version在64位VM上看起来像这样(它明确表示64位): java version "1.7.0_07" Java(TM) SE Runtime Environment (build 1.7.0_07-b10) Java HotSpot(TM) 64-Bit Server VM (build 23.3-b01, mixed mode) java -version will look like this on a 64 bit VM (it explicitly says 64 bits) ...
-
1-是的,他们可以共存。 你不需要任何特殊的配置。 2-是的。 你可以在Eclipse中指定你想要的版本。 窗口>首选项> Java(展开)>已安装的JRE。 3-是的。 你可以安装最新的jdk。 1- Yes they can coexist. You don't need any special configuration. 2- Yes it would. You can specify the version you want in Eclipse. Window > Preferences > J ...
-
如果省略平台属性和-arch开关,则x86(32位)是默认值。 一旦MSI编译完成,无论你的文件被编译为什么,它都将使用32位的位置。 它不知道你的文件中有什么。 我不从命令行做蜡烛/灯光,我使用Visual Studio集成(Votive)/ MSBuild。 在这种情况下,解决方案配置管理器以及x86(默认)和x64的解决方案/项目平台会自动驱动-arch开关。 由于.NET应用程序将JIT任何CPU无论它安装到哪里,我很少创建x64特定的安装程序,因此大多数情况下我忽略这一点。 偶尔,我需要安装和/或 ...
-
我认为这个问题已在这里得到解答: JVM终止了。 退出代码= -1 另见: http : //markonphp.com/solve-error-java-started-returned-exit-code-eclipse/ 希望能帮助到你。 I think this question is already answered here: JVM terminated. Exit code = -1 Also see this: http://markonphp.com/solve-error-java-s ...
-
因为rrdtool是大多数人在unix-ish平台上使用的系统工具,所以实际上你可能会获得更多乐趣,使虚拟ubuntu启动并运行(使用VirtualBox),然后执行 apt-get install rrdtool 而不是经历在Windows上设置unix工具的苦难。 要了解rrdtool,我建议您查看rrdtool网站上的教程。 http://www.rrdtool.org since rrdtool is a system tool most people use on unix-ish platfo ...
-
我强烈建议: 1)安装64位JDK(多个不同的JDK可以在同一主机上共存) 2)启动Eclipse,将项目配置为使用64位Java作为其构建和运行时路径......并查看会发生什么。 它应该工作正常。 除非您的程序碰巧使用SWT(而不是Swing),或者碰巧有其他32/64位依赖项。 3)尝试绝对没有害处。 恕我直言... PS:值得注意的是,您也可以在同一主机上共存多个版本的Eclipse。 您所需要的只是大量的磁盘空间。 在两个版本中重新安装插件和附件的麻烦。 I would strongly reco ...