程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python Tkinter button trigger problem

編輯:Python
The phenomenon and background of the problem

Why does clicking the first registration button execute the function of the second registration button , Ask for solutions

from tkinter import *
import os
from unittest import expectedFailure

user="user.txt"
passwd="passwd.txt"

def show1():
root=Tk()
root.geometry("400x200+800+350")
root.title(" Big ")
label=Label(root,text=" register ",font=(" Chinese Xingkai ",20),fg="green",bg="pink")
label.pack()
#global value1
#value1=Tk.StringVar()
number3=Label(root,text=" user name ")
number3.place(relx=0.2,rely=0.2,anchor=CENTER)
text3=Entry(root)
text3.place(relx=0.5,rely=0.2,anchor=CENTER,width=150,height=25)
#global value2
#value2=Tk.StringVar()
number4=Label(root,text=" password ")
number4.place(relx=0.2,rely=0.4,anchor=CENTER)
text4=Entry(root)
text4.place(relx=0.5,rely=0.4,anchor=CENTER,width=150,height=25)
enter=Button(root,text=" register 1",command=register())
enter.place(relx=0.5,rely=0.8,anchor=CENTER)
#a=str(text3.get())
#b=str(text4.get())

def register():
root=Tk()
root.geometry("200x50+900+450")
root.title(" Big ")
label=Label(root,text=" Registered successfully ",font=(" Chinese Xingkai ",20),fg="green",bg="pink")
label.pack()

def sighin():
print("sighin")

root=Tk()
root.geometry("400x200+800+350")
root.title(" Big ")
label=Label(root,text=" Sign in ",font=(" Chinese Xingkai ",20),fg="green",bg="pink")
label.pack()
number1=Label(root,text=" user name ")
number1.place(relx=0.2,rely=0.2,anchor=CENTER)
text1=Entry(root)
text1.place(relx=0.5,rely=0.2,anchor=CENTER,width=150,height=25)
label.pack()
number2=Label(root,text=" password ")
number2.place(relx=0.2,rely=0.4,anchor=CENTER)
text2=Entry(root)
text2.place(relx=0.5,rely=0.4,anchor=CENTER,width=150,height=25)
enter1=button1=Button(root,text=" register ",command=show1)
enter1.place(relx=0.5,rely=0.8,anchor=CENTER)
enter2=button2=Button(root,text=" Sign in ",command=sighin)
enter2.place(relx=0.5,rely=0.6,anchor=CENTER)
root.mainloop()

Operation results and error reporting contents
My solution ideas and tried methods
What I want to achieve

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved