python不显示关闭窗口按钮_如何在没有按钮的情况下关闭窗口?

我是一个高级计算机专业的学生,我是班上唯一一个会用Python编写代码的人。连我的老师都没学过这门语言。我正在尝试编写一个登录程序,当信息被正确输入并显示欢迎屏幕图像时退出(我还没有对该部分进行编码)。它必须关闭并在3次失败的登录尝试后显示失败消息。在多次登录失败后,尝试更改尝试变量使elif语句工作,以及根据相关的if/elif语句终止/关闭tkinter窗口时,我遇到了许多逻辑错误。这是失败的工作,我已经在这个网站上看了许多代码示例,找不到任何东西,我可以得到一些帮助来修复我的代码吗?在

代码:from tkinter import * #Importing graphics

attempts = 0 #Defining attempts variable

def OperatingProgram(): #Defining active program

class Application(Frame):

global attempts

def __init__(self,master):

super(Application, self).__init__(master) #Set __init__ to the master class

self.grid()

self.InnerWindow() #Creates function

def InnerWindow(self): #Defining the buttons and input boxes within the window

global attempts

print("Booted log in screen")

self.title = Label(self, text=" Please log in, you have " + str(attempts) + " incorrect attempts.") #Title

self.title.grid(row=0, column=2)

self.user_entry_label = Label(self, text="Username: ") #Username box

self.user_entry_label.grid(row=1, column=1)

self.user_entry = Entry(self) #Username entry box

self.user_entry.grid(row=1, column=2)

self.pass_entry_label = Label(self, text="Password: ") #Password label

self.pass_entry_label.grid(row=2, column=1)

self.pass_entry = Entry(self) #Password entry box

self.pass_entry.grid(row=2, column=2)

self.sign_in_butt = Button(self, text="Log In",command = self.logging_in) #Log in button

self.sign_in_butt.grid(row=5, column=2)

def logging_in(self):

global attempts

print("processing")

user_get = self.user_entry.get() #Retrieve Username

pass_get = self.pass_entry.get() #Retrieve Password

if user_get == 'octo' and pass_get == 'burger': #Statement for successful info

import time

time.sleep(2) #Delays for 2 seconds

print("Welcome!")

QuitProgram()

elif user_get != 'octo' or pass_get != 'burger': #Statement for any failed info

if attempts >= 2: #Statement if user has gained 3 failed attempts

import time

time.sleep(2)

print("Sorry, you have given incorrect details too many times!")

print("This program will now end itself")

QuitProgram()

else: #Statement if user still has enough attempts remaining

import time

time.sleep(2)

print("Incorrect username, please try again")

attempts += 1

else: #Statement only exists to complete this if statement block

print("I don't know what you did but it is very wrong.")

root = Tk() #Window format

root.title("Log in screen")

root.geometry("320x100")

app = Application(root) #The frame is inside the widget

root.mainloop() #Keeps the window open/running

def QuitProgram(): #Defining program termination

import sys

sys.exit()

OperatingProgram()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值