I have a series of dialogs that open one after the other. I would like to get all subsequent dialogs to close if I cancel one of them:
import wx
class MainFrame(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, -1, title='GUI Template',size=(200,200))
panel = wx.Panel(self)
sizer = wx.BoxSizer(wx.VERTICAL)
btnSizer = wx.GridBagSizer(hgap=5,vgap=5)
self.onBtn = wx.Button(panel, -1, "Start")
self.Bind(wx.EVT_BUTTON, self.onOn, self.onBtn)
btnSizer.Add(self.onBtn, pos=(0,0))
sizer.Add(btnSizer, flag=wx.CENTER|wx.ALL, border = 5)
panel.SetSizer(sizer)
panel.Fit()
def onOn(self,event):
dlg = wx.SingleChoiceDialog(self, 'Would you Like to add a fruit or a veg?', '', choices=('fruit','veg'))
if dlg.ShowModal() == wx.ID_OK:
addType = dlg.GetStringSelection()
if addType == 'veg':
dlg1 = wx.TextEntryDialog(self, 'Enter veg name')
if dlg1.ShowModal() == wx.ID_OK:
grpName = str(dlg1.GetValue())
print grpName
event.Skip()
if addType == 'fruit':
dlg2 = wx.SingleChoiceDialog(self, 'Choose a type','', choices=('apples','oranges'))
if dlg2.ShowModal() == wx.ID_OK:
group = dlg2.GetStringSelection()
print group
event.Skip()
dlg3 = wx.SingleChoiceDialog(self, 'Which fruit type is this?', '', choices=('red', 'orange', 'yellow'))
if dlg3.ShowModal() == wx.ID_OK:
fType = str(dlg3.GetStringSelection())
print fType
event.Skip()
dlg4 = wx.TextEntryDialog(self, 'Enter name')
if dlg4.ShowModal() == wx.ID_OK:
nName = str(dlg4.GetValue())
print nName
event.Skip()
dlg5 = wx.TextEntryDialog(self, 'Enter address')
if dlg5.ShowModal() == wx.ID_OK:
addr = str(dlg5.GetValue())
print addr
event.Skip()
else:
dlg.Destroy()
if __name__ == "__main__":
app = wx.App(False)
frame = MainFrame(None, 'GUI Template')
frame.Show()
app.MainLoop()
If I click the 'Start' button then highlight 'fruit' and click cancel, no other windows open. If I click 'Start', then 'OK' and try to cancel the next dialog, I have to manually cancel the next 4 dialogs.
I have tried making a closeDialogs function and add an 'else: closeDialogs()' to each 'if' and it didn't work.
I've tried adding this to each dialog:
if dlg2.ShowModal() == wx.ID_CANCEL:
dlg3.Destroy()
dlg4.Destroy()
dlg5.Destroy()
and I get UnboundLocalError: local variable 'dlgX' referenced before assignment error.
I am using Python 2.7 on Windows 10
if addType == 'fruit':
dlg2 = wx.SingleChoiceDialog(self, 'Choose a type','', choices=('apples','oranges'))
if dlg2.ShowModal() == wx.ID_OK:
group = dlg2.GetStringSelection()
print group
event.Skip()
dlg3 = wx.SingleChoiceDialog(self, 'Which fruit type is this?', '', choices=('red', 'orange', 'yellow'))
if dlg3.ShowModal() == wx.ID_OK:
fType = str(dlg3.GetStringSelection())
print fType
event.Skip()
dlg4 = wx.TextEntryDialog(self, 'Enter name')
if dlg4.ShowModal() == wx.ID_OK:
nName = str(dlg4.GetValue())
print nName
event.Skip()
dlg5 = wx.TextEntryDialog(self, 'Enter address')
if dlg5.ShowModal() == wx.ID_OK:
addr = str(dlg5.GetValue())
print addr
event.Skip()
Related
it said the stringvar obj is not callable? i dont know how to fix this can someone help me. thanks
import sqlite3
from tkinter import *
from tkinter import messagebox
i use self.Username etc with a first letter capslock so i can pass it on database connection but it said that stringvar is not callable.
class register:
def __init__(self, window):
self.Username = StringVar()
self.Password = StringVar()
self.Confirm_Password = StringVar()
self.Fullname = StringVar()
self.window = window
self.window.geometry('500x200')
window.resizable(0, 0)
window.configure(bg="deep sky blue")
window.title("Register")
l1 = Label(self.window, text="Username:", font=("Arial", 15), bg="deep sky blue")
l1.place(x=10, y=10)
self.fullname = Entry(self.window, width=30, bd=5, textvariable=self.Fullname)
self.fullname.place(x=200, y=10)
l1 = Label(self.window, text="Username:", font=("Arial", 15), bg="deep sky blue")
l1.place(x=10, y=60)
self.username = Entry(self.window, width=30, bd=5, textvariable=self.Username)
self.username.place(x=200, y=60)
l2 = Label(self.window, text="Password:", font=("Arial", 15), bg="deep sky blue")
l2.place(x=10, y=110)
self.password = Entry(self.window, width=30, show="*", bd=5, textvariable=self.Password)
self.password.place(x=200, y=110)
l3 = Label(self.window, text="Confirm Password:", font=("Arial", 15), bg="deep sky blue")
l3.place(x=10, y=170)
self.confirm_password = Entry(self.window, width=30, show="*", bd=5, textvariable=self.Confirm_Password)
self.confirm_password.place(x=200, y=170)
b1 = Button(self.window, text="Sign in", font=("Arial", 15), bg="#ffc22a", command=self.submit)
b1.place(x=170, y=150)
b2 = Button(self.window, text="Back", font=("Arial", 15), bg="#ffc22a", command=self.submit)
b2.place(x=250, y=150)
heres how i pass it did i make mistake on passing the variable?
connection = sqlite3.connect('RegLog.db')
cur = connection.cursor()
cur.execute("CREATE TABLE IF NOT EXISTS RegLog( username TEXT, Password TEXT, "
"ConfirmPassword TEXT)")
connection.commit()
connection.close()
def submit(self):
check_counter = 0
warn = ""
if self.fullname.get() == "":
warn = "Full Name can't be empty"
else:
check_counter += 1
if self.username.get() == "":
warn = "Full Name can't be empty"
else:
check_counter += 1
if self.password.get() == "":
warn = "Email Field can't be empty"
else:
check_counter += 1
if self.confirm_password.get() == "":
warn = "Sorry, can't sign up make sure all fields are complete"
else:
check_counter += 1
if self.password.get() != self.confirm_password.get():
warn = "Passwords didn't match!"
if check_counter == 4:
try:
connection = sqlite3.connect("RegLog.db")
cur = connection.cursor()
cur.execute("INSERT INTO RegLog values(?,?,?)",
(self.Username.get(), self.Password.get(), self.Confirm_Password.get(), self.Fullname()))
connection.commit()
connection.close()
messagebox.showinfo("Success", "New account created successfully")
and also i think this exception is thrown whenever run the program.it said expected type 'str|None',got 'Exception' instead
except Exception as ep:
messagebox.showerror('Error1', ep)
else:
messagebox.showerror('Error', warn)
def page():
window = Tk()
register(window)
window.mainloop()
I am trying to make a simple app in Tkinter but I ran into a problem. I am trying to use the value that is defined with a Radio Button in a function, but it doesn't seem to work. When I press the Button nothing is printed. What am I doing wrong?
from tkinter import *
window = Tk()
window.title("ALL YOU NEED IS EXCEL")
window.geometry('500x200')
variable_1 = StringVar()
rad1 = Radiobutton(window,text='Button 1', value= "Button 1", variable= variable_1)
rad1.grid(column=0, row=4)
rad2 = Radiobutton(window,text='Button 2', value= "Button 2",variable= variable_1)
rad2.grid(column=1, row=4)
def clicked(vrijednost):
if vrijednost == "Button 1":
print("This is Button 1")
if vrijednost == "Button 2":
print("This is Button 2")
btn = Button(window, text="PRINT", height = 2,width = 15, command=clicked(variable_1))
#btn.grid(column=1, row=5)
btn.place(x = 250, y = 150)
window.mainloop()
Instead of passing the value in the function, you can use vrijednost = variable_1.get() inside the function body itself.
Try the following code:
from tkinter import *
window = Tk()
window.title("ALL YOU NEED IS EXCEL")
window.geometry('500x200')
variable_1 = StringVar()
rad1 = Radiobutton(window,text='Button 1', value= "Button 1", variable= variable_1)
rad1.grid(column=0, row=4)
rad2 = Radiobutton(window,text='Button 2', value= "Button 2",variable= variable_1)
rad2.grid(column=1, row=4)
def clicked():
vrijednost = variable_1.get()
if vrijednost == "Button 1":
print("This is Button 1")
if vrijednost == "Button 2":
print("This is Button 2")
btn = Button(window, text="PRINT", height = 2,width = 15, command=clicked)
#btn.grid(column=1, row=5)
btn.place(x = 250, y = 150)
window.mainloop()
Edit: Adding StringVar() parameter.
However, using walrus operator this can be done quite easily.
code:
from tkinter import *
window = Tk()
window.title("ALL YOU NEED IS EXCEL")
window.geometry('500x200')
variable_1 = StringVar(window, '1')
rad1 = Radiobutton(window,text='Button 1', value= "Button 1", variable= variable_1)
rad1.grid(column=0, row=4)
rad2 = Radiobutton(window,text='Button 2', value= "Button 2",variable= variable_1)
rad2.grid(column=1, row=4)
def clicked():
if (vrijednost := variable_1.get()) == "Button 1":
print("This is Button 1")
else:
print("This is Button 2")
btn = Button(window, text="PRINT", height = 2,width = 15, command=clicked)
btn.place(x = 250, y = 150)
window.mainloop()
Output image:
Output radiobutton2
Hi so I've been working on this project about a day now(New to python and mySQL)
So my question is how i can see if the input user credentials in the textbox is already a registered user?
So far I've managed to connect it to the database and store some values inside the database but i cant seem to figure out how i can scan that database and see if the user info are valid when the login button is pressed.
from tkinter import*
from tkinter import messagebox
import mysql.connector
import time
import datetime
import random
w = 300
h = 2
def register_user():
global username_info
global password_info
if len(username.get()) == 0 and len(password.get()) == 0:
print("Please fill in the Missing Info")
if len(username.get()) == 0 and len(password.get()) != 0 :
print("Please Enter a Username")
elif len(username.get()) != 0 and len(password.get()) == 0:
print("Please enter a Password")
else:
username_info = username.get()
password_info = password.get()
mydb = mysql.connector.connect(
host="localhost",
user="root",
passwd="root",
database="loginsystem"
)
mycursor = mydb.cursor()
sqlFormula = "INSERT INTO users (Username, Password) VALUES (%s, %s)"
insertvar = (username_info, password_info)
user1 = ("Joshua", "Cuyugan")
mycursor.execute(sqlFormula, insertvar)
mydb.commit()
username.set("")
password.set("")
def register():
global screen1
screen.withdraw()
screen1 = Toplevel(screen)
screen1.title("Registration")
screen1.geometry("500x250+700+350")
global username
global password
global username_entry
global password_entry
username = StringVar()
password = StringVar()
Label(screen1, text = " Please Enter Your Details Below", bg = "black", width = w , height = h, font = ("Calibri", 20) , fg = "white").pack()
Label(screen1, text = "").pack()
Label(screen1, text = "Username").place(x=220, y=85)
username_entry = Entry(screen1, textvariable = username, width="50").place(x=100, y=110)
Label(screen1, text = "Password").place(x=220, y=135)
password_entry = Entry(screen1, textvariable = password, width="50").place(x=100, y=160)
Button(screen1, text= "Register", height="1", width="20", command = register_user).place(x=80, y=200)
Button(screen1, text="Cancel", height="1", width="20", command= on_closereg).place(x=270, y=200)
screen1.protocol("WM_DELETE_WINDOW", on_closereg)
def login():
global screen2
mydb = mysql.connector.connect(
host="localhost",
user="root",
passwd="root",
database="loginsystem"
)
mycursor = mydb.cursor()
sql_select_Query = "select * from users"
mycursor.execute(sql_select_Query)
records = mycursor.fetchall()
for row in records:
print("Username" , row[1],)
print("Password", row[2], "\n" )
mycursor.close()
screen.withdraw()
screen2 = Toplevel(screen)
screen2.title("HOT or SUPER HOT")
screen2.geometry("800x600+550+220")
screen2.protocol("WM_DELETE_WINDOW", on_close)
def checker():
if len(username.get()) == 0 and len(password.get()) == 0:
print("Please fill in the Missing Info")
def on_close():
screen2.withdraw()
screen.update()
screen.deiconify()
screen.lift()
def on_closereg():
screen1.withdraw()
screen.update()
screen.deiconify()
screen.lift()
def verify():
global name
global userlogcred
global userpascred
userlogcred = username_verify.get()
userpascred = password_verify.get()
loadname = ("SELECT Username FROM users WHERE Username =%s")
loadpass = ("SELECT Password FFROM users WHERE Password =%s")
mydb = mysql.connector.connect(
host="localhost",
user="root",
passwd="root",
database="loginsystem"
)
mycursor = mydb.cursor()
if len(username_verify.get()) == 0 and len(password_verify.get()) == 0:
print("Please fill in the Missing Info")
if len(username_verify.get()) == 0 and len(password_verify.get()) != 0 :
print("Please Enter a Username")
elif len(username_verify.get()) != 0 and len(password_verify.get()) == 0:
print("Please enter a Password")
else:
mycursor.execute(loadname, userlogcred)
mycursor.execute(loadpass, userpascred)
logincheck = mycursor.fetchone()
loginpasscheck = mycursor.fetchone()
if logincheck is None:
print("Sorry, could not find you in the database\nOr it just isn't working")
if logincheck is not None and loginpasscheck is None:
print("Please Enter your Password")
elif logincheck is None and loginpasscheck is not None:
print("Please enter Your Username")
else:
print("pass\nSuccessfully loaded {} from the database".format(username_verify.get()))
def main_Screen():
global screen
screen = Tk()
screen.geometry("600x300+650+350")
screen.title("Login System")
Label(text = "Login System" , bg = "black", width = w , height = h, font = ("Calibri", 20) , fg = "white").pack()
Label(text = "").pack()
Button(text = "Login", height = h, width = "30", command = verify).place(x=50 , y=200)
Label(text = "").pack()
Button(text = "Register" ,height = h, width = "30", command = register).place(x=320 , y=200)
global username_verify
global password_verify
username_verify = StringVar()
password_verify = StringVar()
Label(screen, text = "Username").place(x=265, y = 90)
username_entry1 = Entry(screen, textvariable = username_verify, width = "80").place(x=57, y=110)
Label(screen, text="Password").place(x=267, y=140)
password_entry1 = Entry(screen, textvariable = password_verify, width = "80").place(x=57, y=160)
screen.mainloop()
main_Screen()
print("Hello World")
Update I Found this code and I'm trying to apply it to my project where in this code compares the input value inside the textbox to the database data and it checks if the datas are already present if they are it then sends you to another form.
def verify():
global name
loadname = ("SELECT Username FROM users WHERE Username =%s")
loadpass = ("SELECT Password FFROM users WHERE Password = %s")
mydb = mysql.connector.connect(
host="localhost",
user="root",
passwd="root",
database="loginsystem"
)
mycursor = mydb.cursor()
if len(username_verify.get()) == 0 and len(password_verify.get()) == 0:
print("Please fill in the Missing Info")
if len(username_verify.get()) == 0 and len(password_verify.get()) != 0 :
print("Please Enter a Username")
elif len(username_verify.get()) != 0 and len(password_verify.get()) == 0:
print("Please enter a Password")
else:
mycursor.execute(loadname, username_verify.get())
mycursor.execute(loadpass, password_verify.get())
logincheck = mycursor.fetchone()
loginpasscheck = mycursor.fetchone()
if logincheck is None:
print("Sorry, could not find you in the database\nOr it just isn't working")
if logincheck is not None and loginpasscheck is None:
print("Please Enter your Password")
elif logincheck is None and loginpasscheck is not None:
print("Please enter Your Username")
else:
print("pass\nSuccessfully loaded {} from the database".format(login))
but I encountered this erro please help.
Traceback (most recent call last):
File "C:\Users\lenovo\AppData\Local\Programs\Python\Python37-32\lib\tkinter\__init__.py", line 1705, in __call__
return self.func(*args)
File "C:/Users/lenovo/PycharmProjects/Pylog/App.py", line 141, in verify
mycursor.execute(loadname, username_verify.get())
File "C:\Users\lenovo\PycharmProjects\Pylog\venv\lib\site-packages\mysql\connector\cursor.py", line 569, in execute
self._handle_result(self._connection.cmd_query(stmt))
File "C:\Users\lenovo\PycharmProjects\Pylog\venv\lib\site-packages\mysql\connector\connection.py", line 553, in cmd_query
result = self._handle_result(self._send_cmd(ServerCmd.QUERY, query))
File "C:\Users\lenovo\PycharmProjects\Pylog\venv\lib\site-packages\mysql\connector\connection.py", line 442, in _handle_result
raise errors.get_exception(packet)
mysql.connector.errors.ProgrammingError: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%s' at line 1
Hello World
Update I put the username_verify.get() values into variables still didn't work and it still posts the same error.
import mysql.connector as sql
class connections:
__HOST = 'localh`o`st'
__USERNAME = 'root'
__PASSWORD = ''
__DATABASE = 'testing'
def __init__(self):
self.con = sql.connect(host=connections.__HOST,user=connections.__USERNAME,password=connections.__PASSWORD,database=connections.__DATABASE)
def connect_database(self,username,password):
#append password and username in the emptey list below for later checkings
mypassword_queue =[]
sql_query = "SELECT *FROM users WHERE first_name ='%s' AND password ='%s'" % (username, password)
mycursor = self.con.cursor()
try:
mycursor.execute(sql_query)
myresults =mycursor.fetchall()
for row in myresults:
for x in row:
mypassword_queue.append(x)
except:
print('error occured')
if (username and password) in mypassword_queue:
print('there is something')
else:
print('there is no anything')
self.con.close()
root = connections()
#---you must have created a database with choice of your database name for this case it is testing
#---- the data inside has name as tumusiime and password 1234
root.connect_database('tumusiime','1234')
I will give you a code that works for me for all querys with mysql.connector
**config= {'user': your_user',
'password': 'your_pass',
'host': 'ip_of_your_db',
'database': 'name_of_your_db',
'raise_on_warnings': True}
def run_query(self,query):
try:
conn = mysql.connector.connect(**self._config)
if conn.is_connected():
print('run_query: Connecting MySql Db')
cur = conn.cursor()
cur.execute(query)
r= cur.fetchall()
return r
except mysql.connector.Error as err:
if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
print("run_query: Error in username or password")
elif err.errno == errorcode.ER_BAD_DB_ERROR:
print("run_query: Dabatase doesn't exist")
else:
print(err)
finally:
conn.commit()
conn.close()
and each Query need to have this format
query='SELECT * FROM {}'.format("your_db.your_table")
answer=self.run_query(query)
I am trying to make a Calculator and the whole thing is almost done, but after the answer has been displayed I want it to reset so a new answer can be displayed. Otherwise it will just be a mess of random number. So I was basically wondering if anyone knew a some sort of reset command that'll work here. More intel is in the code itself(AKA what label). Here's the code:
import time
from tkinter import *
#This is where "Svar" or in English "answer" is being defined.
def Kalk(event):
if operator.get() == "+":
global Svar
Svar = int(Nummer_1.get()) + int(Nummer_2.get())
Answer(event)
elif operator.get() == "-":
Svar = int(Nummer_1.get()) - int(Nummer_2.get())
Answer(event)
elif operator.get() == "*":
Svar = int(Nummer_1.get()) * int(Nummer_2.get())
Answer(event)
elif operator.get() == "/":
Svar = int(Nummer_1.get()) / int(Nummer_2.get())
Answer(event)
else:
Svar = ("Vennligst velg et av alternativene overfor")
Answer(event)
#This is where it displays "Svar" which is "answer".
def Answer(event):
#I want this label("Label_4") to be reset so when I run this def again the numbers won't stack
label_4 = Label(topFrame, text=Svar)
label_4.grid(row=6)
print(Svar)
kalkis = Tk()
kalkis.geometry("300x250")
kalkis.title("Kalkulator")
topFrame = Frame(kalkis)
topFrame.grid(row=0)
label = Label(topFrame, text="Du kan velge mellom '+', '-', '*'. '/' ")
label.grid(row=0)
operator = Entry(topFrame)
operator.grid(row=1)
label_2 = Label(topFrame, text="Skriv inn hvilket tall du vil bruke ")
label_2.grid(row=2)
Nummer_1 = Entry(topFrame)
#Nummer_1 = int(answer.get())
Nummer_1.grid(row=3)
Label_3 = Label(topFrame, text="Skriv inn ditt andre tall ")
Label_3.grid(row=4)
Nummer_2 = Entry(topFrame)
#Nummer_2 = int(answer.get())
Nummer_2.grid(row=5)
#Nummer_2.bind("<Return>", Kalk())
Refresh = Button(topFrame, text="Enter", command=kalkis)
Refresh.bind("<Enter>", Kalk)
Refresh.grid(row=6, column=1, sticky=W)
#Refresh.bind("<Return>", Kalk())
kalkis.mainloop()
An easy way to change a Label() is to associate it to a textvariable of type StringVar(). Any updates to the textvariable will propagate to the label. Eg.
display_text = StringVar()
label_4 = Label(topFrame, textvariable=display_text)
The function Answer() creates a new label each time it is called. Instead just create the label one time and then update the textvariable for each calculation.
import time
from tkinter import *
#This is where "Svar" or in English "answer" is being defined.
def Kalk(event):
if operator.get() == "+":
Svar = int(Nummer_1.get()) + int(Nummer_2.get())
display_text.set(str(Svar)) # Update textvariable
elif operator.get() == "-":
Svar = int(Nummer_1.get()) - int(Nummer_2.get())
display_text.set(str(Svar)) # Update textvariable
elif operator.get() == "*":
Svar = int(Nummer_1.get()) * int(Nummer_2.get())
display_text.set(str(Svar)) # Update textvariable
elif operator.get() == "/":
Svar = int(Nummer_1.get()) / int(Nummer_2.get())
display_text.set(str(Svar)) # Update textvariable
else:
Svar = ("Vennligst velg et av alternativene overfor")
display_text.set(Svar) # Update textvariable
kalkis = Tk()
kalkis.geometry("300x250")
kalkis.title("Kalkulator")
topFrame = Frame(kalkis)
topFrame.grid(row=0)
label = Label(topFrame, text="Du kan velge mellom '+', '-', '*'. '/' ")
label.grid(row=0)
operator = Entry(topFrame)
operator.grid(row=1)
label_2 = Label(topFrame, text="Skriv inn hvilket tall du vil bruke ")
label_2.grid(row=2)
Nummer_1 = Entry(topFrame)
Nummer_1.grid(row=3)
Label_3 = Label(topFrame, text="Skriv inn ditt andre tall ")
Label_3.grid(row=4)
Nummer_2 = Entry(topFrame)
Nummer_2.grid(row=5)
# This is where it displays "Svar" which is "answer".
display_text = StringVar() # Create a StringVar() to hold the result
label_4 = Label(topFrame, textvariable=display_text) # Associate to label
label_4.grid(row=6)
Refresh = Button(topFrame, text="Enter", command=kalkis)
Refresh.bind("<Enter>", Kalk)
Refresh.grid(row=6, column=1, sticky=W)
kalkis.mainloop()
I'm trying to build a program which will create an account and will validate the inputs and place them in a text file. I would be grateful if you could look through my code. The issue I’m having is that I can’t make the message box to pop up when incorrect data is imputed into the text box. I would be very thankful if you could show how to get the message box to show up if the input isn’t valid.
from tkinter import *
from tkinter import messagebox
valid1 = True
valid2 = True
valid3 = True
valid4 = True
valid5 = True
def saveCustomerDetails():
CustomerIDSave = CustomerIDVar.get()
CustomerIDSave = CustomerIDSave.ljust(25)
CustomerTitleSave = CustomerTitleVar.get()
CustomerTitleSave = CustomerTitleSave.ljust(25)
FirstNameSave = FirstNameVar.get()
FirstNameSave = FirstNameSave.ljust(25)
SurnameSave = SurnameVar.get()
SurnameSave = SurnameSave.ljust(25)
DOBSave = DOBVar.get()
DOBSave = DOBSave.ljust(25)
fileObject = open("CreateAccount.txt","a")
fileObject.write(CustomerIDSave + CustomerTitleSave + FirstNameSave + SurnameSave + DOBSave + "\n")
fileObject.close()
def checkID():
global valid1
CustomerID = CustomerIDVar.get()
if CustomerID.isdigit():
valid1 = True
elif CustomerID is "":
valid1 = True
else:
valid1 = False
if valid1 == False:
messagebox.showerror("Incorrect", "Incorrect CustomerID")
def checkTitle():
global valid2
CustomerTitle = CustomerTitleVar.get()
if CustomerTitle.isalpha():
valid2 = True
elif CustomerTitle is "":
valid2 = True
else:
valid2 = False
if valid2 == False:
messagebox.showerror("Incorrect", "Incorrect CustomerID")
def checkFirstName():
global valid3
FirstName = FirstNameVar.get()
if FirstName.isalpha():
valid3 = True
elif FirstName is "":
valid3 = True
else:
valid3 = False
if valid3 == False:
messagebox.showerror("Incorrect", "Incorrect CustomerID")
def checkSurname():
global valid4
Surname = SurnameVar.get()
if Surname.isalpha():
valid4 = True
elif Surname is "":
valid4 = True
else:
valid4 = False
if valid4 == False:
messagebox.showerror("Incorrect", "Incorrect CustomerID")
def checkDOB():
global valid5
DOB = DOBVar.get()
if DOB.isdigit():
valid5 = True
elif DOB is "":
valid5 = True
else:
valid5 = False
if valid5 == False:
messagebox.showerror("Incorrect", "Incorrect CustomerID")
def makeWindow():
global CustomerIDVar, CustomerTitleVar, FirstNameVar, SurnameVar, DOBVar
win = Tk()
win.geometry("700x300")
frame1 = Frame(win)
frame1.pack(side = LEFT)
Label(frame1, text = "Create Account", font = ("Helvetica 12 bold")).grid(row = 0, column = 0)
Label(frame1, text="Customer ID").grid(row=1, column=0, sticky=W)
CustomerIDVar = StringVar()
CustomerID = Entry(frame1, textvariable = CustomerIDVar)
CustomerID.grid(row=1,column=1,sticky=W)
Label(frame1, text="Customer Title").grid(row=2, column=0, sticky=W)
CustomerTitleVar = StringVar()
CustomerTitle = Entry(frame1, textvariable = CustomerTitleVar)
CustomerTitle.grid(row=2,column=1,sticky=W)
Label(frame1, text="First Name").grid(row=3, column=0, sticky=W)
FirstNameVar = StringVar()
FirstName = Entry(frame1, textvariable = FirstNameVar)
FirstName.grid(row=3,column=1,sticky=W)
Label(frame1, text="Last Name").grid(row=4, column=0, sticky=W)
SurnameVar=StringVar()
Surname= Entry(frame1, textvariable=SurnameVar)
Surname.grid(row=4,column=1,sticky=W)
Label(frame1, text="Date Of Birth").grid(row=5, column=0, sticky=W)
DOBVar=StringVar()
DOB = Entry(frame1, textvariable=DOBVar)
DOB.grid(row=5,column=1,sticky=W)
frame2 = Frame(win)
frame2.pack()
b1= Button(frame2, text="Submit", command=saveCustomerDetails)
b1.pack(side = LEFT)
return win
win = makeWindow()
win.mainloop()
You defined a bunch of checks, but you didn't run the functions. For example:
def saveCustomerDetails():
CustomerIDSave = CustomerIDVar.get()
CustomerIDSave = CustomerIDSave.ljust(25)
checkID() #add this to execute the checkID function