def __init__(self): self.win_width, self.win_height = 450, 300 # login in window self.su_win_width, self.su_win_height = 350, 200 # sign up window self.select_win_width, self.select_win_height = 200, 500 # game selection window self.win_pos = get_window_position( win_width, win_height) # for window's center position # window = tk.Tk() # window.title('DogB War') # window.geometry(f'{win_width}x{win_height}+{win_pos[0]}+{win_pos[1]}') self.title('DogB War') self.geometry(f'{win_width}x{win_height}+{win_pos[0]}+{win_pos[1]}') # welcome image self.canvas = tk.Canvas(window, height=200, width=500) self.image_file = tk.PhotoImage(file='images/welcome.gif') self.image = canvas.create_image(0, 0, anchor='nw', image=image_file) self.canvas.pack(side='top') # user information tk.Label(window, text='Username:'******'Password:'******'*****@*****.**', ) self.entry_usr_name = tk.Entry(window, textvariable=var_usr_name) self.entry_usr_name.place(x=160, y=150) # password entry var_usr_pwd = tk.StringVar() entry_usr_pwd = tk.Entry(window, textvariable=var_usr_pwd, show='*') entry_usr_pwd.place(x=160, y=190)
def usr_sign_up(): global su_win_width global su_win_height # sign up logical function def sign_to_db(): nn = new_name.get() np = new_pwd.get() npc = new_pwd_confirm.get() with open('usrs_info.pickle', 'rb') as usr_file: exist_usr_info = pickle.load(usr_file) if nn in exist_usr_info: tk.messagebox.showerror(title='草', message='憨批,非要起跟别人一样的账户名?') elif np == None: tk.messagebox.showerror(title='草', message='憨批,密码不能为空你造马?') elif len(np) < 6: tk.messagebox.showerror(title='草', message='憨批,密码至少得6位你造马?') elif np != npc: tk.messagebox.showerror(title='草', message='憨批,重复密码都能写错?') else: exist_usr_info[nn] = np with open('usrs_info.pickle', 'wb') as usr_file: pickle.dump(exist_usr_info, usr_file) tk.messagebox.showinfo(title='草', message='恭喜这个憨批,成功创建账户!') window_sign_up.destroy() return usr_sign_up() window_sign_up = tk.Toplevel(window) su_win_pos = get_window_position(su_win_width, su_win_height) window_sign_up.geometry( f'{su_win_width}x{su_win_height}+{su_win_pos[0]}+{su_win_pos[1]}') window_sign_up.title('Sign Up Window') new_name = tk.StringVar() new_name.set('*****@*****.**') tk.Label(window_sign_up, text='Username:'******'Password:'******'*') entry_new_pwd.place(x=150, y=50) new_pwd_confirm = tk.StringVar() tk.Label(window_sign_up, text='Confirm password:'******'*') entry_new_pwd_confirm.place(x=150, y=90) btn_confirm_sign_up = tk.Button(window_sign_up, width=8, text='注册', command=sign_to_db) btn_confirm_sign_up.place(x=150, y=130)
def game_window(): global select_win_width global select_win_height window.destroy() # game_select_window = tk.Toplevel(window) game_select_window = tk.Tk() select_win_pos = get_window_position(select_win_width, select_win_height) game_select_window.geometry( f'{select_win_width}x{select_win_height}+{select_win_pos[0]}+{select_win_pos[1]}' ) game_select_window.title('Game selection Window') dogb_war_btn = tk.Button(game_select_window, width=20, text='DogB War', command=start_game1) dogb_war_btn.place(x=20, y=30) dogb_flappy_btn = tk.Button(game_select_window, width=20, text='Flappy BogB', command=start_game2) dogb_flappy_btn.place(x=20, y=60)
import tkinter as tk from tkinter import messagebox import pickle import sys from modules import get_window_position win_width, win_height = 450, 300 # login in window su_win_width, su_win_height = 350, 200 # sign up window win_pos = get_window_position(win_width, win_height) # for window's center position window = tk.Tk() window.title('DogB War') window.geometry(f'{win_width}x{win_height}+{win_pos[0]}+{win_pos[1]}') # welcome image canvas = tk.Canvas(window, height=200, width=500) image_file = tk.PhotoImage(file='images/welcome.gif') image = canvas.create_image(0, 0, anchor='nw', image=image_file) canvas.pack(side='top') # user information tk.Label(window, text='Username:'******'Password:'******'*****@*****.**', ) entry_usr_name = tk.Entry(window, textvariable=var_usr_name) entry_usr_name.place(x=160, y=150)