def quit(self): self.window.destroy() def login_clear(): txt_name.delete(0,tk.END) txt_password.delete(0,tk.END) btn_login = tk.Button(login_win, text="登录", command=login_valid).grid(row=2, column=0,padx=5,pady=5) quit_button = tk.Button(login_win, text="取消", command=self.quit).grid(row=2, column=1,padx=5,pady=5) w_width, w_height = 400, 200 s_width = login_win.winfo_screenwidth() s_height = login_win.winfo_screenheight() x, y = (s_width - w_width) // 2, (s_height - w_height) // 2 login_win.geometry(f"{w_width}x{w_height}+{x}+{y}") window.withdraw()代码有错,帮我改错
时间: 2024-03-12 21:45:57 浏览: 25
在代码中,`self.window`应该改为`login_win`,因为`login_win`是你创建的登录窗口对象。同时,将`quit_button`和`btn_login`定义和布局分开,因为在使用`grid`布局时,需要先定义控件,再进行布局。修改后的代码如下:
```
def quit(self):
login_win.destroy()
def login_clear():
txt_name.delete(0,tk.END)
txt_password.delete(0,tk.END)
login_win = tk.Tk()
login_win.title("登录")
login_win.resizable(False, False)
btn_login = tk.Button(login_win, text="登录", command=login_valid)
btn_login.grid(row=2, column=0,padx=5,pady=5)
quit_button = tk.Button(login_win, text="取消", command=self.quit)
quit_button.grid(row=2, column=1,padx=5,pady=5)
w_width, w_height = 400, 200
s_width = login_win.winfo_screenwidth()
s_height = login_win.winfo_screenheight()
x, y = (s_width - w_width) // 2, (s_height - w_height) // 2
login_win.geometry(f"{w_width}x{w_height}+{x}+{y}")
window.withdraw()
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)