【发布时间】:2019-07-22 17:52:57
【问题描述】:
我想在调整窗口大小(最大化/最小化)时居中的矩形框中显示布局。
import re
import tkinter as tk
root= tk.Tk()
root.title('Password Manager')
#root.iconbitmap("icon.ico") # for icon in gui
root.geometry('500x500')
X=0
Y=0
tk.Label(root,text='User Name : ').place(x=X+0, y=Y+0, in_=root)
signin_user= tk.StringVar() #getting username for signing in
e1=tk.Entry(root,textvariable=signin_user).place(x=X+70, y=Y+0, in_=root) #User name for sign In
tk.Label(root,text='password : ').place(x=X+0, y=Y+25, in_=root)
signin_password=tk.StringVar()
e2=tk.Entry(root,textvariable=signin_password).place(x=X+70, y=Y+25, in_=root) #Password for sign In
def sign_in(): #currently not working
print('hello '+signin_user.get())
#sign In button
tk.Button(root,text="Sign In",width=10,command=sign_in).place(x=X+60,y=Y+50,in_=root)
tk.Label(root,text="Sign up", font='Helvetica 18 bold').place(x=X+50, y=Y+80, in_=root)
tk.Label(root,text="Name : ").place(x=X+0,y=Y+120,in_=root) # Name for register
reg_name=tk.StringVar()
e3 = tk.Entry(root,textvariable=reg_name).place(x=X+50,y=Y+120,in_=root)
tk.Label(root,text="User Name : ").place(x=X+0,y=Y+145,in_=root) #user name to register
reg_user=tk.StringVar()
e4 = tk.Entry(root,textvariable=reg_user).place(x=X+75,y=Y+145,in_=root)
tk.Label(root,text="Password : ").place(x=X+0,y=Y+170,in_=root) #password to register
reg_password=tk.StringVar()
e5 = tk.Entry(root,textvariable=reg_password)
e5.place(x=X+65,y=Y+170,in_=root)
tk.Label(root,text="Confirm password : ").place(x=X+0,y=Y+195,in_=root) #confirm password to register
reg_cnfpassword=tk.StringVar()
e6 = tk.Entry(root,textvariable=reg_cnfpassword).place(x=X+110,y=Y+195,in_=root)
# [] A set of characters "[a-m]"
# \ Signals a special sequence (can also be used to escape special characters) "\d"
# . Any character (except newline character) "he..o"
# ^ Starts with "^hello"
# $ Ends with "world$"
# * Zero or more occurrences "aix*"
# + One or more occurrences "aix+"
# {} Exactly the specified number of occurrences "al{2}"
# | Either or "falls|stays"
# () Capture and group
m=tk.Message(root,text='',fg="red")
m.place(x=X+0,y=Y+250,in_=root)
def sign_up():
regpass = "^[A-Z][\w(!@#$%^&*_+?)+]{8,}$"
if not (re.search(regpass,reg_password.get())):
m.configure(text='''->Spaces and empty sets are not allowed.
\n ->First character should be a capital letter.
\n ->Password must be greater than 8 character and must contain a special character.''')
elif (reg_password != reg_cnfpassword):
m.configure(text='Password and Confirm Password must match')
else :
m.configure(text='')
#sign Up button
tk.Button(root,text="Sign Up",width=10,command=sign_up).place(x=X+80,y=Y+225,in_=root)
root.mainloop()
我曾尝试将其框定出来,但没有成功。 我也尝试过 pack() 来解决,但再次失败。 还请给出使用任何方法获得所需输出的逻辑
【问题讨论】:
-
您的代码难以阅读和理解。我强烈建议您阅读并开始关注PEP 8 - Style Guide for Python Code,尤其是如果您希望其他人帮助您修复它。
-
为了使代码可读,将所有定义的函数放在
root = Tk()之前,并将所有StringVar组合在一个地方,并阅读PEP 8 -- Style Guide for Python Code
标签: python python-3.x tkinter tkinter-canvas