[英]Pop up warning box
我有一種方法可以檢查是否已輸入pyqt旋轉框值,所需的值是1到18(含1和18),所以我將旋轉框的值設置為0,這樣我就可以很容易地告訴它未更改為正確的數字。 我以為如果檢查發現它仍然為0,用戶會忘記設置它,並彈出警告讓他們知道。。我的問題是窗口彈出,用戶按OK,彈出窗口關閉,但立即又打開在用戶有時間設置正確的值之前...如何關閉彈出窗口,並讓用戶有時間將旋轉框更改為正確的值,然后再檢查0並再次彈出(如果仍然不正確)
觸發group_check的信號最初是觸發pickFile方法的,直到我意識到無論執行代碼是否在Spinbox中設置了代碼,我都嘗試將檢查構建到pickFile方法中,但是盡管也許最好將其分離出。
import sys
import time
from PyQt4 import QtGui, uic
import xlrd
import csv
import os
import re
qtCreatorFile = "UI1.ui" # Enter file here.
Ui_MainWindow, QtBaseClass = uic.loadUiType(qtCreatorFile)
class MyApp(QtGui.QMainWindow, Ui_MainWindow):
group = ''
group_1 = ''
Var_1 = ''
Var_2 = ''
Var_3 = ''
error_string = ''
def __init__(self):
QtGui.QMainWindow.__init__(self)
Ui_MainWindow.__init__(self)
self.setupUi(self)
self.file_picker_button.clicked.connect(self.group_check)
self.radioButton_1.clicked.connect(self.onRadioButton1)
self.radioButton_2.clicked.connect(self.onRadioButton2)
self.radioButton_3.clicked.connect(self.onRadioButton3)
self.spinBox.valueChanged.connect(self.valuechange)
def group_check(self):
while True:
if self.spinBox.value() == 0:
error_string ='You must select your\nGroup No first ! ok ? '
self.error_msg(error_string)
else:
self.pickFile()
def pickFile(self):
while True:
filename = QtGui.QFileDialog.getOpenFileName(self, 'Open File', '.')
if 'Monday' in filename:
break
elif 'Monday' not in filename or filename == '':
error_string ='Wrong file ? \nWant to try again ?'
self.error_msg1(error_string)
else:
self.filename = filename
x = first_file()
x.csv_from_excel(filename)
def onRadioButton1(self, group):
MyApp.Var_1 = 'PGDE SECONDARY ONLY'
MyApp.Var_2 = 'MA4 ONLY'
MyApp.Var_3 = 'PGDE'
def onRadioButton2(self, group):
MyApp.Var_1 = 'PGDE PRIMARY ONLY'
MyApp.Var_2 = 'MA4 ONLY'
MyApp.Var_3 = 'PGDE'
def onRadioButton3(self, group):
MyApp.Var_1 = 'PGDE PRIMARY ONLY'
MyApp.Var_2 = 'PGDE SECONDARY ONLY'
MyApp.Var_3 = 'MA4'
def valuechange(self, value):
MyApp.group_1 = ('Group '+ str(self.spinBox.value()))
if self.spinBox.value() >= 10:
MyApp.group = "1-9 ONLY"
if self.spinBox.value() >= 1 and self.spinBox.value() <= 9:
MyApp.group = "10-18 ONLY"
def error_msg(self, error_string):
choice = QtGui.QMessageBox.question(self, 'Error!', error_string)
而不是使用while True
僅顯示錯誤消息並從函數返回。 解決錯誤后,請他們再次單擊該按鈕
def group_check(self):
if self.spinBox.value() == 0:
error_string ='You must select your\nGroup No first ! ok ? '
self.error_msg(error_string)
return
self.pickFile()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.