|

楼主 |
发表于 2021-7-9 22:00:42
|
显示全部楼层
本帖最后由 Wirror 于 2021-7-9 22:03 编辑
我还有一个文件如果在主函数里Tk()一个对象窗口就可以在Application类里quit掉
- #!/usr/bin/env python
- #-*- coding:utf-8 -*-
- from people import *
- from Main_Window import *
- from tkinter import *
- import tkinter.messagebox
- import os, sys
- try:
- from tkinter import *
- except ImportError: #Python 2.x
- PythonVersion = 2
- from Tkinter import *
- from tkFont import Font
- from ttk import *
- #Usage:showinfo/warning/error,askquestion/okcancel/yesno/retrycancel
- from tkMessageBox import *
- #Usage:f=tkFileDialog.askopenfilename(initialdir='E:/Python')
- #import tkFileDialog
- #import tkSimpleDialog
- else: #Python 3.x
- PythonVersion = 3
- from tkinter.font import Font
- from tkinter.ttk import *
- from tkinter.messagebox import *
- #import tkinter.filedialog as tkFileDialog
- #import tkinter.simpledialog as tkSimpleDialog #askstring()
- class Application_ui(Frame):
- #这个类仅实现界面生成功能,具体事件处理代码在子类Application中。
- def __init__(self, master=None):
- Frame.__init__(self, master)
- self.master.title('登录')
- self.master.geometry('900x471')
- self.master.resizable(0,0)
- self.createWidgets()
- def createWidgets(self):
- self.top = self.winfo_toplevel()
- self.style = Style()
- self.style.configure('Quit.TButton',font=('宋体',9))
- self.Quit = Button(self.top, text='退出', command=self.Quit_Cmd, style='Quit.TButton')
- self.Quit.place(relx=0.764, rely=0.696, relwidth=0.126, relheight=0.087)
- self.style.configure('Ok.TButton',font=('宋体',9))
- self.Ok = Button(self.top, text='登录', command=self.Ok_Cmd, style='Ok.TButton')
- self.Ok.place(relx=0.613, rely=0.696, relwidth=0.126, relheight=0.087)
- self.PassWordVar = StringVar(value='')
- self.PassWord = Entry(self.top, show='*', textvariable=self.PassWordVar, font=('宋体',9))
- self.PassWord.place(relx=0.596, rely=0.425, relwidth=0.339, relheight=0.07)
- self.WorkNumberVar = StringVar(value='')
- self.WorkNumber = Entry(self.top, textvariable=self.WorkNumberVar, font=('宋体',9))
- self.WorkNumber.place(relx=0.596, rely=0.306, relwidth=0.339, relheight=0.07)
- self.style.configure('Label2.TLabel',anchor='center', background='#3399FF', font=('宋体',14))
- self.Label2 = Label(self.top, text='', style='Label2.TLabel')
- self.Label2.place(relx=0.329, rely=0.934, relwidth=0.294, relheight=0.053)
- self.style.configure('Label1.TLabel',anchor='center', foreground='#FF8000', background='#00FFFF', font=('宋体',48))
- self.Label1 = Label(self.top, text='', style='Label1.TLabel')
- self.Label1.place(relx=0.142, rely=0.374, relwidth=0.196, relheight=0.221)
- self.style.configure('L3.TLabel',anchor='w', font=('宋体',18))
- self.L3 = Label(self.top, text='工号', style='L3.TLabel')
- self.L3.place(relx=0.516, rely=0.306, relwidth=0.072, relheight=0.07)
- self.style.configure('Label3.TLabel',anchor='w', font=('宋体',18))
- self.Label3 = Label(self.top, text='密码', style='Label3.TLabel')
- self.Label3.place(relx=0.516, rely=0.425, relwidth=0.072, relheight=0.07)
- self.style.configure('set.TButton',font=('宋体',9))
- self.set = Button(self.top, text='注册用户', command=self.set_Cmd, style='set.TButton')
- self.set.place(relx=0.853, rely=0.849, relwidth=0.108, relheight=0.046)
- class Application(Application_ui):
- #这个类实现具体的事件处理回调函数。界面生成代码在Application_ui中。
- def __init__(self, master=None):
- Application_ui.__init__(self, master)
- def Quit_Cmd(self, event=None):
- top.quit()
- def show(self, event=None):
- top.update()
- top.deiconify()
- def Ok_Cmd(self, event=None):
- if self.PassWord.get() == '12345':
- top.withdraw()# 这里可以正常关闭
- main_window()
- top.quit()
- else:
- self.PassWord.delete(0, END)
- tkinter.messagebox.askokcancel\
- (title = '密码错误',message='密码错误!')
- def set_Cmd(self, event=None):
- people_set()
- if __name__ == "__main__":
- top = Tk()
- Application(top).mainloop()
- try: top.destroy()
- except: pass
复制代码 |
|