当我使用循环“ while”时,我的GUI的PYQT5项目不会出现。检查是否检查了复选框
我正在编码一个将货币转换为您从列表框选择的其他货币的程序。
我在这个程序上遇到了麻烦。如果我在检查时使用循环,我的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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是评论中建议的示例。
您可以使用按钮
切换
信号,然后使用setone
方法作为插槽。该信号以布尔值作为参数表示,并指示该检查状态,然后可以将其用于有条件地执行某些操作。每次更改按钮的状态时,信号都会自动发出,因此无需循环。Here is an example of what is suggested in the comments.
You connect with the buttons
toggled
signal and use yoursetOne
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.