我正在开发一些应用程序。我想创建一个工具栏,点击后将打开设置窗口。但是我不知道该怎么做。现在的方法是,我有一个工具栏图标连接到ShowSettings函数。每次我单击图标时,这个函数都会创建一个新的设置实例(我知道它不应该每次都创建一个新实例,而应该在开始时创建一个实例,然后再处理它。但我不知道如何做),然后显示与此实例关联的设置窗口。然而,窗口只会以这种方式闪烁一秒钟。我不知道怎么了希望你能帮助我:)import sys

import time

from PyQt4 import QtCore, QtGui

from ui import Ui_MainWindow

from ui import Ui_SettingsWindow

#Aplikacja obslugujaca bramki LF

#zamiana pliku .ui na kod pythona

#pyuic4 untitled.ui -o output.py

class timerThread(QtCore.QThread):

timeElapsed = QtCore.pyqtSignal(float)

def __init__(self, parent=None):

super(timerThread, self).__init__(parent)

self.timeStart = None

def start(self, timeStart):

self.timeStart = timeStart

return super(timerThread, self).start()

def run(self):

while self.parent().isRunning():

self.timeElapsed.emit(time.time() - self.timeStart)

time.sleep(0.1)

class myThread(QtCore.QThread):

timeElapsed = QtCore.pyqtSignal(float)

def __init__(self, parent=None):

super(myThread, self).__init__(parent)

self.timerThread = timerThread(self)

self.timerThread.timeElapsed.connect(self.timeElapsed.emit)

def run(self):

self.timerThread.start(time.time())

iterations = 10000000000

while iterations:

print "Running {0}".format(self.__class__.__name__)

iterations -= 1

time.sleep(10)

class SettingsWindow(QtGui.QMainWindow):

#Constructor:

def __init__(self, parent=None):

QtGui.QWidget.__init__(self, parent)

self.ui_settigns = Ui_SettingsWindow()

self.ui_settigns.setupUi(self)

class MainWindow(QtGui.QMainWindow):

#Constructor:

def __init__(self, parent=None):

QtGui.QWidget.__init__(self, parent)

self.ui = Ui_MainWindow()

self.ui.setupUi(self)

self.myThread = myThread(self)

self.myThread.timeElapsed.connect(self.on_myThread_timeElapsed)

self.myThread.finished.connect(self.on_myThread_finished)

#Nie wiem jak przerzucic to do pliku UI bez errorow

#Toolbar

settingsAction = QtGui.QAction(QtGui.QIcon('tools.jpg'), 'Ustawienia', self)

settingsAction.setShortcut('Ctrl+U')

settingsAction.triggered.connect(self.ShowSettings)

self.toolbar = self.addToolBar('Settings')

self.toolbar.addAction(settingsAction)

def UpdateList(self):

contest_name = self.ui.comboBox.currentText()

#jakis try-catch tutaj sie przyda gdyby nie plik nie istnial

#zczytuje z pliku liste robotow

with open('database\%s.txt' % contest_name) as f:

robots_list = f.read().splitlines()

self.ui.listWidget.clear()

self.ui.listWidget.addItems(robots_list)

def Search(self):

text = self.ui.lineEdit.text()

self.ui.lineEdit.clear()

item = self.ui.listWidget.findItems(text, QtCore.Qt.MatchExactly)

#jakiegos try-catcha trzeba tutaj walnac

self.ui.listWidget.setItemSelected(item[0], True)

def ShowSettings(self):

settings = SettingsWindow() #creates settings instance

settings.show()

@QtCore.pyqtSlot()

def on_button_clicked(self):

self.myThread.start()

@QtCore.pyqtSlot(int)

def on_myThread_timeElapsed(self, seconds):

self.ui.lcdNumber.display(seconds)

@QtCore.pyqtSlot()

def on_myThread_finished(self):

self.myThread.terminate()

print "Done"

if __name__ == "__main__":

app = QtGui.QApplication(sys.argv)

myapp = MainWindow()

settings = SettingsWindow()

myapp.show()

settings.show()

sys.exit(app.exec_())

这是用户界面文件

^{pr2}$

python切换消息窗_如何使用PyQ在python中的两个窗口之间切换相关推荐

  1. python windows 消息通讯_在windows下使用python进行串口通讯的方法

    在windows下使用python进行串口通讯的方法 Windows版本下的python并没有内置串口通讯的pyserial的库,所以需要自己下载.参照了网上的教程,有许多用的pip的安装方式,但是试 ...

  2. python切换消息窗_用Python切换窗口

    The way that user had defined find_window only allows you to choose by the classname of the window 用 ...

  3. python新手入门教程思路-Python新手入门教程_教你怎么用Python做数据分析

    Python新手入门教程_教你怎么用Python做数据分析 跟大家讲了这么多期的Python教程,有小伙伴在学Python新手教程的时候说学Python比较复杂的地方就是资料太多了,比较复杂.很多网上 ...

  4. python队列线程池_实例详解:python高级编程之消息队列(Queue)与进程池(Pool)

    今天为大家带来的内容是:python高级编程之消息队列(Queue)与进程池(Pool),结合了实例的形式详细分析了Python消息队列与进程池的相关原理.使用技巧与操作注意事项!!! Queue消息 ...

  5. python代码编写工具_编写更好的Python代码的终极指南

    python代码编写工具 Despite its 尽管它 downsides, Python remains the king of today's programming world. Its ve ...

  6. python应用程序开发者_用 NVIDIA ISAAC-SDK 在 Python 中开发机器人应用程序

    图 1 .使用 Jupyter 笔记本和 ISAAC SDK Python API 在 ISAAC Sim 中控制虚拟机器人. NVIDIA ISAAC 软件开发工具包 的模块化和易于使用的感知堆栈继 ...

  7. python executemany执行延迟_运维架构师-Python 自动化运维开发-031

    *运维架构师-Python 自动化运维开发-031 十九.Python3 操作数据库 1.Python3 操作 MySQL 1.基本介绍 Python3 操作 MySQL 数据库 可以使用的模块是 p ...

  8. python按键暂停程序_汇总程序员学习python必备的42个快捷键,看完收获满满

    很多程序员在学习python的时候,是否遇到过一些操作不方便且很繁琐小问题,特别还会影响到你工作的进度,或许这50个快捷键能够帮助到你哦! 首先先从Shift系列的按键开始: 1. Shift+Alt ...

  9. 阿里云python自测答案_阿里云技能测试python初级中级高级

    简介 偶尔发现,阿里云-开发者社区,里竟然有技能测试平台 覆盖知识面也较多 初级(65) 涉及知识点:Python语言的基本特性.编程环境.语法基础.数据结构,了解Python的网络编程与Web开发, ...

最新文章

  1. python读取excel数据并饼图_python生成excel表格以及饼图 示例源码
  2. linux终端获取root,ubuntu18.04获取root权限并用root用户登录的实现
  3. 关于Kingfisher--备用
  4. spring 源码分析01
  5. 每天一小时python官方文档学习(三)————函数
  6. Linux 文件夹权限
  7. JDK 9 对字符串 String 的优化,挺有意思!
  8. 记录一次阻塞引发的系统超时
  9. 著名设计师的标志(Logo)设计观
  10. linux系统,清理缓冲池内存
  11. C++编程 中文转换成Unicode
  12. 情人节程序员用HTML网页表白【时光不老,我们不散love520】 HTML5七夕情人节表白网页源码 HTML+CSS+JavaScript
  13. UE4 图表插件使用文档
  14. 魔兽世界架设 mysql_魔兽世界单机版局域网的架设方法
  15. php接入腾讯云短信SDK
  16. MP4视频损坏修复工具下载
  17. 初学者福利:分享五个免费的 Python 学习网站,抓紧收藏吧
  18. 我的世界启动器+账号+密码
  19. Arduino框架下ESP8266获取和风天气的第三方库实现天气时钟制作思路
  20. Python数据库篇

热门文章

  1. 基于JAVA养老院老人日常生活管理系统计算机毕业设计源码+系统+mysql数据库+lw文档+部署
  2. 法切蒂:真正的球迷是不会中途退场
  3. 车机开发问题: igo导航无audio focus机制导致声音焦点被抢走
  4. 软件工程--牙科诊所--需求获取
  5. 科技爱好者周刊(第 191 期):一个程序员的财务独立之路
  6. new Date处理日期格式及兼容浏览器问题
  7. 家政服务App平台的市场前景
  8. 作为精益敏捷根基的科学管理与福特、大野耐一、戴明、德鲁克
  9. 优秀java实习报告范文5篇
  10. SQL Server数据库登陆失败,无法连接数据库