当我使用循环“ while”时,我的GUI的PYQT5项目不会出现。检查是否检查了复选框

发布于 2025-02-13 19:43:15 字数 940 浏览 1 评论 0原文

我正在编码一个将货币转换为您从列表框选择的其他货币的程序。

我在这个程序上遇到了麻烦。如果我在检查时使用循环,我的GUI项目不会出现在我身上。

这是我的代码:

from selenium import webdriver
from selenium.webdriver.common.by import By as by
from selenium.webdriver.common.keys import Keys as key
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from interface import *
import time
import sys

class CurrencyConverter(QMainWindow):
    def __init__(self):
        super().__init__()
        self.ui = Ui_Interface()
        self.ui.setupUi(self)
        self.show()
        self.ui.amountbox.setVisible(1)
        self.stepOne()

    def stepOne(self):
        while True:
            if self.ui.Amount.isChecked():
                self.ui.amountbox.setVisible(0)
            else:
                self.ui.amountbox.setVisible(1)

if __name__ == '__main__':
    app = QApplication(sys.argv)
    myWindow = CurrencyConverter()
    app.exec_()

I'm coding a program that converts a currency into the other currency you choosed from the ListBox.

I'm having trouble with this program. If I use the loop while to check, items of my Gui does not appear to me.

Here are my codes:

from selenium import webdriver
from selenium.webdriver.common.by import By as by
from selenium.webdriver.common.keys import Keys as key
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from interface import *
import time
import sys

class CurrencyConverter(QMainWindow):
    def __init__(self):
        super().__init__()
        self.ui = Ui_Interface()
        self.ui.setupUi(self)
        self.show()
        self.ui.amountbox.setVisible(1)
        self.stepOne()

    def stepOne(self):
        while True:
            if self.ui.Amount.isChecked():
                self.ui.amountbox.setVisible(0)
            else:
                self.ui.amountbox.setVisible(1)

if __name__ == '__main__':
    app = QApplication(sys.argv)
    myWindow = CurrencyConverter()
    app.exec_()

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

陌路终见情 2025-02-20 19:43:15

这是评论中建议的示例。

您可以使用按钮切换信号,然后使用setone方法作为插槽。该信号以布尔值作为参数表示,并指示该检查状态,然后可以将其用于有条件地执行某些操作。每次更改按钮的状态时,信号都会自动发出,因此无需循环。

...

class CurrencyConverter(QMainWindow):
    def __init__(self):
        super().__init__()
        ...
        ...
 
        self.ui.amount.toggled.connect(self.stepOne)  # signal connection

    def setOne(self, ischecked):   # slot method
        if ischecked:    
            self.ui.amountbox.setVisible(0)
        else:
            self.ui.amountbox.setVisible(1)

Here is an example of what is suggested in the comments.

You connect with the buttons toggled signal and use your setOne method as the slot. The signal is emited with a boolean value as an argument indicating the checkstate which you can then use to conditionally perform some action. The signal is automatically emitted every time the state of the button is changed, so no while loops are necessary.

...

class CurrencyConverter(QMainWindow):
    def __init__(self):
        super().__init__()
        ...
        ...
 
        self.ui.amount.toggled.connect(self.stepOne)  # signal connection

    def setOne(self, ischecked):   # slot method
        if ischecked:    
            self.ui.amountbox.setVisible(0)
        else:
            self.ui.amountbox.setVisible(1)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文