from PyQt5.uic import loadUi from PyQt5.QtWidgets import QWidget class History(QWidget): def init(self,name): super().init(name) self.setParent(name) loadUi('ui/history.ui',self) #设定控件属性 self.history_text.setReadOnly(True) #—————————————————————————————————————————绑定信号—————————————————————————————————————————— self.btn_cancel.clicked.connect(lambda:self.hide())修改代码使得History部件不隐藏
时间: 2023-07-27 09:07:40 浏览: 154
如果您想让 `History` 部件不隐藏,只需要将 `self.hide()` 这行代码注释掉即可。修改后的代码如下:
```python
from PyQt5.uic import loadUi
from PyQt5.QtWidgets import QWidget
class History(QWidget):
def __init__(self, name):
super().__init__(name)
self.setParent(name)
loadUi('ui/history.ui', self)
# 设定控件属性
self.history_text.setReadOnly(True)
# 绑定信号
self.btn_cancel.clicked.connect(lambda:self.hide())
```
这样做会在 `History` 部件初始化时将其显示出来,并且不会隐藏。
相关问题
import sys import threading import time from PyQt5.QtWidgets import * from PyQt5 import uic import pandas as pd import random # import pyqtgraph as pg import matplotlib.pyplot as plt from PyQt5.QtWidgets import QGroupBox from PyQt5 import QtWidgets from login_4 import Ui_CK from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas # df = pd.read_excel('shu.xlsx') class MyWindow(QWidget and QMainWindow,Ui_CK): def __init__(self): super().__init__() self.init_ui() groupbox = QGroupBox('Title',self) # self.plot = pg.PlotWidget(enableAutoRange=True) # self.ui.verticalLayout.addWidget(self.plot) # self.curve = self.plot.plot() #self.ui = uic.loadUi("./login_4.ui") def init_ui(self): print('1.1') try: self.ui = uic.loadUi("./login_4.ui") #print(threading.current_thread()) #print(self.ui.__dict__) # print(self.ui.label) # print(self.ui.label.text()) # 查看ui文件中有哪些控件 # 提取要操作的控件 self.user_name_qwidget = self.ui.lineEdit # 单位输入框 self.password_qwidget = self.ui.lineEdit_2 # 二级单位输入框 self.zhicheng_qwidget = self.ui.lineEdit_3 # 职称输入框 self.jiaoyuan_qwidget = self.ui.lineEdit_4 # 教员输入框 self.login_btn = self.ui.pushButton # 登录抽课按钮 self.textBrowser = self.ui.textBrowser # 授课对象显示区域 # 绑定信号与槽函数 self.textBrowser_2 = self.ui.textBrowser_2 # 文本显示区域课程名称 self.textBrowser_3 = self.ui.textBrowser_3 # 文本显示区域课次 self.textBrowser_4 = self.ui.textBrowser_4 # 文本显示区域教研室 self.login_btn.clicked.connect(self.login) self.login_btna = self.ui.pushButton_2 self.login_btna.clicked.connect(lambda: self.plot_q()) except Exception as e: print(e.__class__.__name__, e) def login(self): print('1.2') """登录按钮的槽函数""" #print(self.user_name_qwidget.text()) a = self.user_name_qwidget.text() e = sel 为什么会报错
这是一段Python代码,通过使用import关键字导入了sys、threading、time等模块。同时,也导入了PyQt5.QtWidgets的部分类和PyQt5.uic模块。此外,还导入了pandas和random模块,用于处理数据和生成随机数等操作。
使用QTimer对象代替QBasicTimer对象,修改程序class MyWindow(QWidget): def init(self): super().init() self.thread_list = [] self.color_photo_dir = os.path.join(os.getcwd(), "color_photos") self.depth_photo_dir = os.path.join(os.getcwd(), "depth_photos") self.image_thread = None self.saved_color_photos = 0 # 定义 saved_color_photos 属性 self.saved_depth_photos = 0 # 定义 saved_depth_photos 属性 self.init_ui() def init_ui(self): self.ui = uic.loadUi("C:/Users/wyt/Desktop/D405界面/intelrealsense1.ui") self.open_btn = self.ui.pushButton self.color_image_chose_btn = self.ui.pushButton_3 self.depth_image_chose_btn = self.ui.pushButton_4 self.open_btn.clicked.connect(self.open) self.color_image_chose_btn.clicked.connect(lambda: self.chose_dir(self.ui.lineEdit, "color")) self.depth_image_chose_btn.clicked.connect(lambda: self.chose_dir(self.ui.lineEdit_2, "depth")) def open(self): self.profile = self.pipeline.start(self.config) self.is_camera_opened = True self.label.setText('相机已打开') self.label.setStyleSheet('color:green') self.open_btn.setEnabled(False) self.close_btn.setEnabled(True) self.image_thread = ImageThread(self.pipeline, self.color_label, self.depth_label, self.interval, self.color_photo_dir, self.depth_photo_dir, self._dgl) self.image_thread.saved_color_photos_signal.connect(self.update_saved_color_photos_label) self.image_thread.saved_depth_photos_signal.connect(self.update_saved_depth_photos_label) self.image_thread.start() def chose_dir(self, line_edit, button_type): my_thread = MyThread(line_edit, button_type) my_thread.finished_signal.connect(self.update_line_edit) self.thread_list.append(my_thread) my_thread.start()
以下是使用QTimer对象代替QBasicTimer对象的修改后的代码:
```python
from PyQt5.QtCore import QTimer
class MyWindow(QWidget):
def __init__(self):
super().__init__()
self.thread_list = []
self.color_photo_dir = os.path.join(os.getcwd(), "color_photos")
self.depth_photo_dir = os.path.join(os.getcwd(), "depth_photos")
self.image_thread = None
self.saved_color_photos = 0
self.saved_depth_photos = 0
self.init_ui()
def init_ui(self):
self.ui = uic.loadUi("C:/Users/wyt/Desktop/D405界面/intelrealsense1.ui")
self.open_btn = self.ui.pushButton
self.color_image_chose_btn = self.ui.pushButton_3
self.depth_image_chose_btn = self.ui.pushButton_4
self.open_btn.clicked.connect(self.open)
self.color_image_chose_btn.clicked.connect(lambda: self.chose_dir(self.ui.lineEdit, "color"))
self.depth_image_chose_btn.clicked.connect(lambda: self.chose_dir(self.ui.lineEdit_2, "depth"))
def open(self):
self.profile = self.pipeline.start(self.config)
self.is_camera_opened = True
self.label.setText('相机已打开')
self.label.setStyleSheet('color:green')
self.open_btn.setEnabled(False)
self.close_btn.setEnabled(True)
self.image_thread = ImageThread(self.pipeline, self.color_label, self.depth_label, self.interval, self.color_photo_dir, self.depth_photo_dir, self._dgl)
self.image_thread.saved_color_photos_signal.connect(self.update_saved_color_photos_label)
self.image_thread.saved_depth_photos_signal.connect(self.update_saved_depth_photos_label)
self.image_thread.start()
self.timer = QTimer(self) # 创建QTimer对象
self.timer.timeout.connect(self.update) # 连接timeout信号与槽函数
self.timer.start(100) # 启动定时器,间隔为100ms
def update(self):
# 检查所有的线程是否已完成,并从线程列表中移除已完成的线程
for thread in self.thread_list:
if not thread.isRunning():
self.thread_list.remove(thread)
def chose_dir(self, line_edit, button_type):
my_thread = MyThread(line_edit, button_type)
my_thread.finished_signal.connect(self.update_line_edit)
self.thread_list.append(my_thread)
my_thread.start()
def update_saved_color_photos_label(self, count):
self.saved_color_photos = count
self.ui.label_5.setText(str(self.saved_color_photos))
def update_saved_depth_photos_label(self, count):
self.saved_depth_photos = count
self.ui.label_6.setText(str(self.saved_depth_photos))
```
阅读全文