I am calling my function mTime to get the values from 4 Entryboxes, to check the time, if there is a value my code works without a problem but if the entrybox is empty, just like ' ', I mean the user delete the default values in the entryboxes which are '0'. and leave it empty I want to assign a value of '0' if this happens
but it is not working!
my code
def mTime():
if (len(str(Days_T.get())) == 0):
dd = Days_T.set(0)
else:
dd = Days_T.get()
if (len(str(Hours_T.get())) == 0):
hh = Hours_T.set(0)
else:
hh = Hours_T.get()
if (len(str(Minutes_T.get())) == 0):
mm = Minutes_T.set(1)
else:
mm = Minutes_T.get()
if (len(str(Seconds_T.get())) == 0):
ss = Seconds_T.set(0)
else:
ss = Seconds_T.get()
d = dd
h = hh
m = mm
s = ss
print (dd,hh,mm,ss)
Days_T = IntVar()
Hours_T = IntVar()
Minutes_T = IntVar()
Seconds_T = IntVar()
TDays = Entry(mGui, textvariable = Days_T, width = 4, justify = CENTER).place(x=520,y=260)
THours = Entry(mGui, textvariable = Hours_T, width = 4, justify = CENTER).place(x=550,y=260)
TMinutes = Entry(mGui, textvariable = Minutes_T, width = 4, justify = CENTER).place(x=580,y=260)
TSeconds = Entry(mGui, textvariable = Seconds_T, width = 4, justify = CENTER).place(x=610,y=260)
mTime()
I am getting this error
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python34\lib\tkinter\__init__.py", line 1533, in __call__
return self.func(*args)
File "C:\Users\me\Desktop\Project\ManualTab.py", line 908, in mTime
if (len(str(Minutes_T.get())) == 0):
File "C:\Python34\lib\tkinter\__init__.py", line 358, in get
return getint(self._tk.globalgetvar(self._name))
ValueError: invalid literal for int() with base 10: ''
EDITED
NEW CODE
ddays = StringVar()
ddays.set(Days_T.get())
hhours = StringVar()
hhours.set(Hours_T.get())
mminutes = StringVar()
mminutes.set(Minutes_T.get())
sseconds = StringVar()
sseconds.set(Seconds_T.get())
if (len(ddays) == 0):
dd = Days_T.set(2)
else:
dd = Days_T.get()
if (len(hhours) == 0):
hh = Hours_T.set(0)
else:
hh = Hours_T.get()
if (len(mminutes) == 0):
mm = Minutes_T.set(0)
else:
mm = Minutes_T.get()
if (len(sseconds) == 0):
ss = Seconds_T.set(0)
else:
ss = Seconds_T.get()
d = dd
h = hh
m = mm
s = ss
print (dd,hh,mm,ss)
Days_T = IntVar()
Hours_T = IntVar()
Minutes_T = IntVar()
Seconds_T = IntVar()
TDays = Entry(mGui, textvariable = Days_T, width = 4, justify = CENTER).place(x=520,y=260)
THours = Entry(mGui, textvariable = Hours_T, width = 4, justify = CENTER).place(x=550,y=260)
TMinutes = Entry(mGui, textvariable = Minutes_T, width = 4, justify = CENTER).place(x=580,y=260)
TSeconds = Entry(mGui, textvariable = Seconds_T, width = 4, justify = CENTER).place(x=610,y=260)
mTime()
BUT IS NOT WORKING