我正在为一个软件的GUI工作,该软件可以为不同的客户端自动输入数据,现在我正在实现第一个客户端称为加利西亚,我不能让浏览按钮工作,这是应该允许用户浏览一个文件,其中的数据存储在。目前它甚至没有真正的React作为一个按钮。(默认情况下,PyQt中的按钮在鼠标悬停时有一个蓝色的边框覆盖,甚至没有响应。
这是我的代码
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QComboBox, QPushButton
from PyQt5.QtGui import QIcon, QStandardItemModel, QStandardItem
from PyQt5.QtWidgets import (
QApplication, QMainWindow, QWidget, QLabel, QLineEdit,
QPushButton, QFileDialog, QProgressBar
)
from PyQt5.QtCore import Qt, QThread, pyqtSignal, QSize
from analysis import analyze
class WorkerThread(QThread):
progress_changed = pyqtSignal(int)
def run(self):
# Here you can put your own code to be executed in the main loop
for i in range(101):
self.progress_changed.emit(i)
self.msleep(50)
class GaliciaGUI(QWidget):
def __init__(self):
super().__init__()
central_widget = QWidget(self)
self.search_label = QLabel("Search for a file:", central_widget)
self.search_label.setGeometry(50, 50, 170, 30)
self.search_button = QPushButton("Browse", central_widget)
self.search_button.setGeometry(50, 80, 80, 30)
self.search_button.clicked.connect(self.browse_file)
self.date_start = QLabel("Fecha:", central_widget)
self.date_start.setGeometry(350, 50, 170, 30)
self.date_start_input = QLineEdit(central_widget)
self.date_start_input.setGeometry(350, 80, 250, 30)
self.date_start_input = QLineEdit(central_widget)
self.date_start_input.setGeometry(50, 150, 200, 30)
self.date_start_input.setEchoMode(QLineEdit.Password)
self.selected_file_label = QLabel("", central_widget)
self.selected_file_label.setGeometry(50, 80, 300, 30)
self.password_label = QLabel("Enter password:", central_widget)
self.password_label.setGeometry(50, 120, 150, 30)
self.password_input = QLineEdit(central_widget)
self.password_input.setGeometry(50, 150, 200, 30)
self.password_input.setEchoMode(QLineEdit.Password)
self.start_button = QPushButton("Start", central_widget)
self.start_button.setGeometry(50, 190, 80, 30)
self.start_button.clicked.connect(self.start_main_loop)
self.progress_bar = QProgressBar(central_widget)
self.progress_bar.setGeometry(50, 230, 300, 30)
self.progress_bar.setValue(0)
self.status_label = QLabel("", central_widget)
self.status_label.setGeometry(50, 250, 150, 30)
self.file_path = None
self.worker_thread = WorkerThread()
self.worker_thread.progress_changed.connect(self.update_progress_bar)
def browse_file(self):
file_path, _ = QFileDialog.getOpenFileName(
self, "Select a file", "", "All Files (*);;Text Files (*.txt)"
)
if file_path:
self.selected_file_label.setText(f"Selected file: {file_path}")
self.file_path = file_path
def start_main_loop(self):
password = self.password_input.text() or None
if self.file_path:
self.worker_thread.start()
analyze(self.file_path, password)
def update_progress_bar(self, value):
self.progress_bar.setValue(value)
if value == 100:
self.status_label.setText("Success")
class LandingPage(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle('Client Selection')
self.setGeometry(100, 100, 400, 300)
self.client_label = QLabel('Select a client:', self)
self.client_label.move(50, 50)
self.client_dropdown = QComboBox(self)
self.client_dropdown.addItems(['Galicia', 'Client 2', 'Client 3']) # Add more clients here
self.client_dropdown.move(150, 50)
self.submit_button = QPushButton('Submit', self)
self.submit_button.move(150, 100)
self.submit_button.clicked.connect(self.open_gui)
self.galicia_gui = None # Initialize instance variable for GaliciaGUI
self.show()
def open_gui(self):
client = self.client_dropdown.currentText()
if client == 'Galicia':
self.galicia_gui = GaliciaGUI()
self.galicia_gui.setGeometry(100, 100, 700, 600)
self.galicia_gui.activateWindow()
self.galicia_gui.raise_()
self.galicia_gui.show()
app = QApplication.instance()
app.setActiveWindow(self.galicia_gui)
elif client == 'Client 2':
# Open Client 2 GUI
pass # Replace client
elif client == 'Client 3':
# Open Client 3 GUI
pass # Replace with client
if __name__ == '__main__':
app = QApplication(sys.argv)
landing_page = LandingPage()
app.exec_()
我试图实现一个按钮,它带来了文件资源管理器(这个软件是为windows),其中一个可以浏览所需的文件,然后说文件是通过分析功能输入到数据处理。
1条答案
按热度按时间wgx48brx1#
是固定检查
display
(别忘了验证答案,谢谢)