python 控件失去焦点_显示信息警报时,Python tkinter窗口失去焦点(Python tkinter window loses focus when an info alert is d...

I am constructing a basic login system in tkinter (python), When the user enters their details to register, I want to display a tkmessagebox that will tell them if there are any errors in their input.

When the GUI loads initially, they are asked if they would like to login or register (works fine). Say the user clicks Register, they are brought to a second screen to enter their details (also works fine). From here, when they enter their details and click register, if the error alert displays, the register part of the GUI loses focus and disappears behind the first part of the GUI where the user would of chosen to go to the register screen.

Is there any way to prevent my child window from loosing focus when an alert is shown?

def registerCheck(self):

#print('Username: '+ str(self.UN.get()))

errorList = ''

if self.UN.get() == '':

errorList += 'Username cannot be empty\n'

if len(self.PW.get()) < 4:

errorList += 'Password must be more than 4 characters long\n'

if self.PW.get() != self.PWCF.get():

errorList += 'Passwords do not match\n'

if len(self.Email.get()) < 5:

errorList += 'Email is not valid\n'

if errorList == '':

tkMessageBox.showinfo(title="About", message="No Errors Found")

else:

tkMessageBox.showerror(title="Errors Found!", message=errorList)

return

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值