Posts: 37
Threads: 12
Joined: Jul 2021
Aug-03-2021, 06:26 AM
(This post was last modified: Aug-10-2021, 07:51 AM by Larz60+.
Edit Reason: fixed error tags
)
Hi all I am experiencing a strange issue.
I have two scripts in tkinter one is for date picker from a calender when i run the script it runs perfectly.
# Import Required Library
from tkinter import *
from tkcalendar import Calendar
# Create Object
root = Tk()
# Set geometry
root.geometry("400x400")
# Add Calendar
cal = Calendar(root, selectmode = 'day',
year = 2020, month = 5,
day = 22)
cal.pack(pady = 20)
def grad_date():
date.config(text = "Selected Date is: " + cal.get_date())
# Add Button and Label
Button(root, text = "Get Date",
command = grad_date).pack(pady = 20)
date = Label(root, text = "")
date.pack(pady = 20)
# Excecute Tkinter
root.mainloop() The second script is something i am working on. I want to insert the date picker in the GUI . I have a current date , which is required . the date picker is to select the delivery date. when I add the above mentioned date picker script to my script I get an error Error: Traceback (most recent call last):
File "C:\Users\INDIAN\Desktop\python exercises\order form\order form - Copy 4.py", line 5, in <module>
from tkcalender import Calender
ModuleNotFoundError: No module named 'tkcalender'
here is the code.
from tkinter import *
import tkinter as tk
import datetime as dt
from tkinter import ttk
from tkcalender import Calender
#win=tk.Tk()
#win.title('Lab Order Form')
root = Tk()
root.title("Lab Order Form")
d = f'{dt.datetime.now():%a, %b %d %Y}'
cal = Calendar(root, selectmode = 'day',
year = 2020, month = 5,
day = 22)
cal.pack(pady = 20)
def grad_date():
date.config(text = "Selected Date is: " + cal.get_date())
# Add Button and Label
Button(root, text = "Get Date",
command = grad_date).pack(pady = 20)
date = Label(root, text = "")
date.pack(pady = 20)
def getvals():
print("Submitting form")
print(f"{labnamevalue.get(),patientnamevalue.get(), workvalue.get(), toothnumbervalue.get(), materialvalue.get(), shadevalue.get(), labservicevalue.get()} ",d,de)
with open("records.txt", "a") as f:
f.write(f"{labnamevalue.get(),patientnamevalue.get(), workvalue.get(), toothnumbervalue.get(), materialvalue.get(), shadevalue.get(), labservicevalue.get()}\n ")
root.geometry("644x344")
#Heading
Label(root, text="Arora Dental Care\n Lab Work Order ", font="comicsansms 13 bold", pady=15).grid(row=0, column=5)
#Text for our form
labname = Label(root, text=" Lab. Name")
patientname=Label(root, text=" Patient.Name")
orderdate=Label(root, text="Order Date")
date=Label(root,text=d,fg="black", bg="white",font=("Helvetica", 11))
work = Label(root, text="Work Required")
toothnumber = Label(root, text="Tooth Number")
material = Label(root, text="Material")
shade = Label(root, text="Shade")
#Pack text for our form
labname.grid(row=1, column=2,padx=5,pady=5)
patientname.grid(row=1, column=5,padx=5,pady=5)
orderdate.grid(row=2, column=5,padx=5,pady=5)
date.grid(row=2,column=7,padx=5,pady=5)
work.grid(row=2, column=2,padx=5,pady=5)
toothnumber.grid(row=3, column=2,padx=5,pady=5)
material.grid(row=4, column=2,padx=5,pady=5)
shade.grid(row=5, column=2,padx=5,pady=5)
# Tkinter variable for storing entries
labnamevalue = StringVar()
patientnamevalue = StringVar()
orderdatevalue= StringVar()
workvalue = StringVar()
toothnumbervalue = StringVar()
materialvalue = StringVar()
shadevalue = StringVar()
labservicevalue = IntVar()
#Entries for our form
labnameentry = Entry(root, width=23,textvariable=labnamevalue)
patientnameentry = Entry(root,width=23, textvariable=patientnamevalue)
#orderdateentry=Entry(root,textvariable=orderdatevalue)
workentry =ttk.Combobox(root,width=20,textvariable=workvalue)
workentry['values']=("Crown","Bridge","Onlay","Inlay","Veneer")
workentry.current()
#workentry = Entry(root, textvariable=workvalue)
toothnumberentry =ttk.Combobox(root,width=20,textvariable=toothnumbervalue)
toothnumberentry['values']=("18","17","16","15","14","13","12","11","21","22","23","24","25","26","27","28","38","37","36","35","34","33","32","31","41","42","43","44","45","46","47","48")
toothnumberentry.current()
materialentry =ttk.Combobox(root,width=20,textvariable=materialvalue)
materialentry['values']=("PFM","Zirconia","NiCr","NiCr+Ceramic facing","EMax")
materialentry.current()
#materialentry = Entry(root, textvariable=materialvalue)
shadeentry =ttk.Combobox(root,width=20,textvariable=shadevalue)
shadeentry['values']=("A1","A2","A3","A3.5","A4","B1","B2","B3","B4","C1","C2","C3","C4","D2","D3","D4")
shadeentry.current()
#shadeentry = Entry(root, textvariable=shadevalue)
# Packing the Entries
labnameentry.grid(row=1, column=3,padx=5,pady=5)
patientnameentry.grid(row=1, column=7,padx=5,pady=5)
#orderdateentry.grid(row=2, column=7)
workentry.grid(row=2, column=3,padx=5,pady=5)
toothnumberentry.grid(row=3, column=3,padx=5,pady=5)
materialentry.grid(row=4, column=3,padx=5,pady=5)
shadeentry.grid(row=5, column=3,padx=5,pady=5)
#Checkbox & Packing it
labservice = Checkbutton(text="Want metal coping trial", variable = labservicevalue)
labservice.grid(row=7, column=3)
#Button & packing it and assigning it a command
Button(text=" submit ", command=getvals).grid(row=13, column=3)
root.mainloop() I know there is something wrong , but am unable to figure it out. Can somebody help.
Posts: 1,838
Threads: 2
Joined: Apr 2017
The module name is wrong - you've got a typo in the word "calendar". Compare line 4 in the first piece of code with line 5 in the second.
Posts: 12,033
Threads: 486
Joined: Sep 2016
there's also a geometry error. You're not allowed to use both grid and pack in the same container, use all one or the other.
Posts: 37
Threads: 12
Joined: Jul 2021
(Aug-03-2021, 09:47 AM)Larz60+ Wrote: there's also a geometry error. You're not allowed to use both grid and pack in the same container, use all one or the other.
Thanks Larzo60. But i am still unable to solve the problem. I want the date to be a drop down box.This is the code I have worked out but its not working.( the code for calender is not mine I copied it from one of the tutorials and am trying to insert it in my existing code). I am a newbie and trying to learn. can you please explain me how to go about it . from tkinter import *
import tkinter as tk
import datetime as dt
from tkinter import ttk
from tkcalendar import DateEntry
from datetime import date
root = Tk()
root.title("Lab Order Form")
photo=PhotoImage(file="C:\\Users\\INDIAN\\Desktop\\python exercises\\order form\\tooth1.png")
label = Label(root,image = photo,bg="light blue")
label.image = photo # keep a reference!
label.grid(row=5,column=3,columnspan=20,sticky=tk.W,rowspan=20)
#style = ttk.Style(root)
#style.theme_use('clam')
class MyDateEntry(DateEntry):
def __init__(self, master=None, **kw):
DateEntry.__init__(self, master=None, **kw)
# add black border around drop-down calendar
self._top_cal.configure(bg='black', bd=1)
# add label displaying today's date below
tk.Label(self._top_cal, bg='gray90', anchor='w',
text='Today: %s' % date.today().strftime('%x')).pack(fill='x')
# create the entry and configure the calendar colors
de = MyDateEntry(root, year=2016, month=9, day=6,
selectbackground='gray80',
selectforeground='black',
normalbackground='white',
normalforeground='black',
background='gray90',
foreground='black',
bordercolor='gray90',
othermonthforeground='gray50',
othermonthbackground='white',
othermonthweforeground='gray50',
othermonthwebackground='white',
weekendbackground='white',
weekendforeground='black',
headersbackground='white',
headersforeground='gray70')
#de.pack()
d = f'{dt.datetime.now():%a, %b %d %Y}'
def getvals():
print("Submitting form")
print(f"{labnamevalue.get(),patientnamevalue.get(),patientagevalue.get(),patientsexvalue.get(), workvalue.get(), toothnumbervalue.get(), materialvalue.get(), incisalvalue.get(),middlevalue.get(),cervicalvalue.get(), labservicevalue.get(),toothreductionvalue.get(),reductioncopingvalue.get(),sendbackvalue.get()} ",d,d)
with open("records.txt", "a") as f:
f.write(f"{labnamevalue.get(),patientnamevalue.get(),patientagevalue.get(),patientsexvalue.get(), workvalue.get(), toothnumbervalue.get(), materialvalue.get(), incisalvalue.get(),middlevalue.get(),cervicalvalue.get(), labservicevalue.get(),toothreductionvalue.get(),reductioncopingvalue.get(),sendbackvalue.get()}\n")
root.geometry("500x300")
root.configure(background='light blue')
#root.resizable(False, False)
#Heading
Label(root, text="Arora Dental Care\n Lab Work Order\n Crown ", font="comicsansms 13 bold",bg="light blue", pady=15).grid(row=0, column=2)
#Text for our form
labname = Label(root, text=" Lab. Name",bg="light blue")
patientname=Label(root, text=" Patient.Name",bg="light blue")
patientage=Label(root, text="Patient Age",bg="light blue")
patientsex=Label(root,text="Sex",bg="light blue")
orderdate=Label(root, text="Order Date",bg="light blue")
date=Label(root,text=d,fg="black",bg="light blue",font=("Helvetica", 11))
reqdate=Label(root,text=MyDateEntry)
work = Label(root, text="Work Required",bg="light blue")
toothnumber = Label(root, text="Tooth Number",bg="light blue")
material = Label(root, text="Material",bg="light blue")
shade = Label(root, text="Shade",bg="light blue")
incisal=Label(root,text="Incisal/occlusal 1/3rd",bg="light blue")
middle=Label(root,text="Middle 1/3rd",bg="light blue")
cervical=Label(root,text="Cervical 1/3rd",bg="light blue")
lessspace=Label(root,text=" In Case of inadequate occlussal clearance",font='Helvetica 18 bold', bg="light blue")
#Pack text for our form
labname.grid(row=1, column=0,padx=5,pady=5)
patientname.grid(row=1, column=2,padx=5,pady=5)
patientage.grid(row=2,column=2, padx=5,pady=5)
patientsex.grid(row=3,column=2,padx=5,pady=5)
orderdate.grid(row=4, column=2,padx=5,pady=5)
reqdate.grid(row=5,column=2,padx=5,pady=5)
date.grid(row=4,column=3,sticky=tk.W,padx=5,pady=5)
work.grid(row=2, column=0,padx=5,pady=5)
toothnumber.grid(row=3, column=0,padx=5,pady=5)
material.grid(row=4, column=0,padx=5,pady=5)
shade.grid(row=5, column=0,padx=5,pady=5)
incisal.grid(row=6,column=0,padx=5,pady=5)
middle.grid(row=7,column=0,padx=5,pady=5)
cervical.grid(row=8,column=0,padx=5,pady=5)
lessspace.grid(row=10,column=2)
# Tkinter variable for storing entries
labnamevalue = StringVar()
patientnamevalue = StringVar()
patientagevalue=StringVar()
patientsexvalue=StringVar()
orderdatevalue= StringVar()
workvalue = StringVar()
toothnumbervalue = StringVar()
materialvalue = StringVar()
#shadevalue = StringVar()
incisalvalue=StringVar()
middlevalue=StringVar()
cervicalvalue=StringVar()
labservicevalue = IntVar()
toothreductionvalue=IntVar()
reductioncopingvalue=IntVar()
sendbackvalue=IntVar()
#Entries for our form
labnameentry = Entry(root, width=23,textvariable=labnamevalue)
patientnameentry = Entry(root,width=23, textvariable=patientnamevalue)
patientageentry=Entry(root,width=6, textvariable=patientagevalue)
patientsexentry=ttk.Combobox(root,width=6,textvariable=patientsexvalue)
patientsexentry['values']=("M","F")
patientsexentry.current()
#orderdateentry=Entry(root,textvariable=orderdatevalue)
workentry =ttk.Combobox(root,width=20,textvariable=workvalue)
workentry['values']=("Crown","Bridge","Onlay","Inlay","Veneer")
workentry.current()
#workentry = Entry(root, textvariable=workvalue)
toothnumberentry =ttk.Combobox(root,width=20,textvariable=toothnumbervalue)
toothnumberentry['values']=("18","17","16","15","14","13","12","11","21","22","23","24","25","26","27","28","38","37","36","35","34","33","32","31","41","42","43","44","45","46","47","48")
toothnumberentry.current()
materialentry =ttk.Combobox(root,width=20,textvariable=materialvalue)
materialentry['values']=("PFM","Zirconia","NiCr","NiCr+Ceramic facing","EMax")
materialentry.current()
#materialentry = Entry(root, textvariable=materialvalue)
#shadeentry =ttk.Combobox(root,width=20,textvariable=shadevalue)
#shadeentry['values']=("A1","A2","A3","A3.5","A4","B1","B2","B3","B4","C1","C2","C3","C4","D2","D3","D4")
#shadeentry.current()
#shadeentry = Entry(root, textvariable=shadevalue)
incisalentry =ttk.Combobox(root,width=6,textvariable=incisalvalue)
incisalentry['values']=("A1","A2","A3","A3.5","A4","B1","B2","B3","B4","C1","C2","C3","C4","D2","D3","D4")
incisalentry.current()
middleentry =ttk.Combobox(root,width=6,textvariable=middlevalue)
middleentry['values']=("A1","A2","A3","A3.5","A4","B1","B2","B3","B4","C1","C2","C3","C4","D2","D3","D4")
middleentry.current()
cervicalentry =ttk.Combobox(root,width=6,textvariable=cervicalvalue)
cervicalentry['values']=("A1","A2","A3","A3.5","A4","B1","B2","B3","B4","C1","C2","C3","C4","D2","D3","D4")
cervicalentry.current()
# Packing the Entries
labnameentry.grid(row=1, column=1,padx=5,pady=5)
patientnameentry.grid(row=1, column=3,sticky=tk.W,padx=5,pady=5)
patientageentry.grid(row=2, column=3,sticky=tk.W,padx=5,pady=5)
patientsexentry.grid(row=3, column=3,sticky=tk.W,padx=5,pady=5)
#orderdateentry.grid(row=2, column=7)
workentry.grid(row=2, column=1,padx=5,pady=5)
toothnumberentry.grid(row=3, column=1,padx=5,pady=5)
materialentry.grid(row=4, column=1,padx=5,pady=5)
#shadeentry.grid(row=5, column=3,padx=5,pady=5)
incisalentry.grid(row=6, column=1,sticky=tk.W,padx=5,pady=5)
middleentry.grid(row=7, column=1,sticky=tk.W,padx=5,pady=5)
cervicalentry.grid(row=8, column=1,sticky=tk.W,padx=5,pady=5)
#Checkbox & Packing it
labservice = Checkbutton(text="Want metal coping trial",bg="light blue", variable = labservicevalue)
labservice.grid(row=9, column=2,sticky=tk.W)
toothreduction = Checkbutton(text="Do opposite tooth reduction",bg="light blue", variable = toothreductionvalue)
toothreduction.grid(row=11, column=2,sticky=tk.W)
reductioncoping = Checkbutton(text="Make reduction coping",bg="light blue", variable = reductioncopingvalue)
reductioncoping.grid(row=12, column=2,sticky=tk.W)
sendback = Checkbutton(text="Send the Case Back for correction",bg="light blue", variable = sendbackvalue)
sendback.grid(row=13, column=2,sticky=tk.W)
#Button & packing it and assigning it a command
Button(text=" submit ", command=getvals).grid(row=15, column=2)
root.mainloop()
Posts: 12,033
Threads: 486
Joined: Sep 2016
at minimum. show the error traceback (complete and unaltered) that you are receiving.
Also supply what's needed to run (tooth1.png, etc.)
As a rule, you should write a small amount of code, get it working and then build on it.
trying to write so much code at once without doing so is difficult at best,
You also need to learn how to containerize your code into functions and methods rather than writing one big serial code.
Posts: 37
Threads: 12
Joined: Jul 2021
I (Aug-09-2021, 10:02 AM)Larz60+ Wrote: at minimum. show the error traceback (complete and unaltered) that you are receiving.
Also supply what's needed to run (tooth1.png, etc.)
As a rule, you should write a small amount of code, get it working and then build on it.
trying to write so much code at once without doing so is difficult at best,
You also need to learn how to containerize your code into functions and methods rather than writing one big serial code. Hi
I have not written this code in one go. I started of with one label and entry and then gradually kept on adding to it. The code works fine till I add the class for my calendar. Now when I run it doesn't give any trace back only the tooth.png is displayed. I am unable to understand where I am going wrong. I think I am not understanding how to use the" class ". And how to integrate it with the existing code. I want to display a drop-down combobox for selecting a date which will be displayed in the combobox and printed to the console.
Posts: 6,804
Threads: 20
Joined: Feb 2020
Aug-09-2021, 05:58 PM
(This post was last modified: Aug-09-2021, 05:58 PM by deanhystad.)
Your DateEntry will not appear in root window.
class MyDateEntry(DateEntry):
def __init__(self, master=None, **kw):
DateEntry.__init__(self, master=None, **kw) # Overrides whatever is passed as "master". Call without =None And what is _top_cal?
class MyDateEntry(DateEntry):
def __init__(self, master=None, **kw):
DateEntry.__init__(self, master=None, **kw)
# add black border around drop-down calendar
self._top_cal.configure(bg='black', bd=1) # What?
# add label displaying today's date below
tk.Label(self._top_cal, bg='gray90', anchor='w',
text='Today: %s' % date.today().strftime('%x')).pack(fill='x') I looked up the source and found that _top_cal is a Toplevel window. This is not mentioned in the documentation and the leading underscore in _top_cal infers that this is supposed to be a private attribute. Unless you really, really need a black background and 1 pixel border, I would remove references to things that are not in the API.
It is likely that your program is crashing trying to add the datetime widget, but tkinter catches a lot of exceptions and tries to muddle on. If you move the code creating the datetime widget further down in you program you will see more widgets in your form. This is a debugging trick, not a fix. If you can see all the widgets added before DateEntry and none added after, it is likely the problem is with adding DateEntry.
Posts: 37
Threads: 12
Joined: Jul 2021
(Aug-09-2021, 05:58 PM)deanhystad Wrote: Your DateEntry will not appear in root window.
class MyDateEntry(DateEntry):
def __init__(self, master=None, **kw):
DateEntry.__init__(self, master=None, **kw) # Overrides whatever is passed as "master". Call without =None And what is _top_cal?
class MyDateEntry(DateEntry):
def __init__(self, master=None, **kw):
DateEntry.__init__(self, master=None, **kw)
# add black border around drop-down calendar
self._top_cal.configure(bg='black', bd=1) # What?
# add label displaying today's date below
tk.Label(self._top_cal, bg='gray90', anchor='w',
text='Today: %s' % date.today().strftime('%x')).pack(fill='x') I looked up the source and found that _top_cal is a Toplevel window. This is not mentioned in the documentation and the leading underscore in _top_cal infers that this is supposed to be a private attribute. Unless you really, really need a black background and 1 pixel border, I would remove references to things that are not in the API.
It is likely that your program is crashing trying to add the datetime widget, but tkinter catches a lot of exceptions and tries to muddle on. If you move the code creating the datetime widget further down in you program you will see more widgets in your form. This is a debugging trick, not a fix. If you can see all the widgets added before DateEntry and none added after, it is likely the problem is with adding DateEntry. Thanks deanhystad. I have worked out a the code and I am getting the drop down date picker on my form where I want it. But I am facing 3 issues.
1) The selected Date from the date picker is not printing to the console.
2) The date format i get is MM/DD/YY. i would like it to be DD/MM/YYYY.
3) The checkbox values printing in console are ,1,1 . i know they are default meaning true. But I would like to print "Yes" in case the value is 1( checkbox checked) and "No" in case the value is 0( checkbox not checked)
My present code is: from tkinter import *
import tkinter as tk
import datetime as dt
from tkinter import ttk
from tkcalendar import DateEntry
root = Tk()
root.title("Lab Order Form")
#photo=PhotoImage(file="C:\\Users\\INDIAN\\Desktop\\python exercises\\order form\\crown2.png")
#label = Label(root,image = photo,bg="light blue")
#label.image = photo # keep a reference!
#label.grid(row=7,column=3,columnspan=20,sticky=tk.E,rowspan=30)
d = f'{dt.datetime.now():%a, %b %d %Y}'
cal = DateEntry(root, width=12, day=20, month=6, year=22,
background='darkblue', foreground='white', borderwidth=2)
#,cal.pack(padx=10, pady=10)
def getvals():
print("Submitting form")
print(f"{labnamevalue.get(),patientnamevalue.get(),patientagevalue.get(),patientsexvalue.get(), workvalue.get(), reqdatevalue.get(),toothnumbervalue.get(), materialvalue.get(), incisalvalue.get(),middlevalue.get(),cervicalvalue.get(), labservicevalue.get(),toothreductionvalue.get(),reductioncopingvalue.get(),sendbackvalue.get()} ",d)
with open("records.txt", "a") as f:
f.write(f"{labnamevalue.get(),patientnamevalue.get(),patientagevalue.get(),patientsexvalue.get(), workvalue.get(),reqdatevalue.get(), toothnumbervalue.get(), materialvalue.get(), incisalvalue.get(),middlevalue.get(),cervicalvalue.get(), labservicevalue.get(),toothreductionvalue.get(),reductioncopingvalue.get(),sendbackvalue.get()}\n")
root.geometry("500x300")
root.configure(background='light blue')
#root.resizable(False, False)
#Heading
Label(root, text="Arora Dental Care\n Lab Work Order\n Crown ", font="comicsansms 13 bold",bg="light blue", pady=15).grid(row=0, column=2)
#Text for our form
labname = Label(root, text=" Lab. Name",bg="light blue")
patientname=Label(root, text=" Patient.Name",bg="light blue")
patientage=Label(root, text="Patient Age",bg="light blue")
patientsex=Label(root,text="Sex",bg="light blue")
orderdate=Label(root, text="Order Date",bg="light blue")
date=Label(root,text=d,fg="black",bg="light blue",font=("Helvetica", 11))
reqdate=Label(root,text="Deliver By",bg="light blue")
work = Label(root, text="Work Required",bg="light blue")
toothnumber = Label(root, text="Tooth Number",bg="light blue")
material = Label(root, text="Material",bg="light blue")
shade = Label(root, text="Shade",bg="light blue")
incisal=Label(root,text="Incisal/occlusal 1/3rd",bg="light blue")
middle=Label(root,text="Middle 1/3rd",bg="light blue")
cervical=Label(root,text="Cervical 1/3rd",bg="light blue")
lessspace=Label(root,text=" In Case of inadequate occlussal clearance",font='Helvetica 18 bold', bg="light blue")
#Pack text for our form
labname.grid(row=1, column=0,padx=5,pady=5)
patientname.grid(row=1, column=2,padx=5,pady=5)
patientage.grid(row=2,column=2, padx=5,pady=5)
patientsex.grid(row=3,column=2,padx=5,pady=5)
orderdate.grid(row=4, column=2,padx=5,pady=5)
reqdate.grid(row=5, column=2,padx=5,pady=5)
date.grid(row=4,column=3,sticky=tk.W,padx=5,pady=5)
work.grid(row=2, column=0,padx=5,pady=5)
toothnumber.grid(row=3, column=0,padx=5,pady=5)
material.grid(row=4, column=0,padx=5,pady=5)
shade.grid(row=5, column=0,padx=5,pady=5)
incisal.grid(row=6,column=0,padx=5,pady=5)
middle.grid(row=7,column=0,padx=5,pady=5)
cervical.grid(row=8,column=0,padx=5,pady=5)
lessspace.grid(row=10,column=2)
# Tkinter variable for storing entries
labnamevalue = StringVar()
patientnamevalue = StringVar()
patientagevalue=StringVar()
patientsexvalue=StringVar()
orderdatevalue= StringVar()
reqdatevalue=StringVar()
workvalue = StringVar()
toothnumbervalue = StringVar()
materialvalue = StringVar()
#shadevalue = StringVar()
incisalvalue=StringVar()
middlevalue=StringVar()
cervicalvalue=StringVar()
labservicevalue = IntVar()
toothreductionvalue=IntVar()
reductioncopingvalue=IntVar()
sendbackvalue=IntVar()
#Entries for our form
labnameentry = Entry(root, width=23,textvariable=labnamevalue)
patientnameentry = Entry(root,width=23, textvariable=patientnamevalue)
patientageentry=Entry(root,width=6, textvariable=patientagevalue)
patientsexentry=ttk.Combobox(root,width=6,textvariable=patientsexvalue)
patientsexentry['values']=("M","F")
patientsexentry.current()
DateEntry=cal
#orderdateentry=Entry(root,textvariable=orderdatevalue)
workentry =ttk.Combobox(root,width=20,textvariable=workvalue)
workentry['values']=("Crown","Bridge","Onlay","Inlay","Veneer")
workentry.current()
#workentry = Entry(root, textvariable=workvalue)
toothnumberentry =ttk.Combobox(root,width=20,textvariable=toothnumbervalue)
toothnumberentry['values']=("18","17","16","15","14","13","12","11","21","22","23","24","25","26","27","28","38","37","36","35","34","33","32","31","41","42","43","44","45","46","47","48")
toothnumberentry.current()
materialentry =ttk.Combobox(root,width=20,textvariable=materialvalue)
materialentry['values']=("PFM","Zirconia","NiCr","NiCr+Ceramic facing","EMax")
materialentry.current()
#materialentry = Entry(root, textvariable=materialvalue)
#shadeentry =ttk.Combobox(root,width=20,textvariable=shadevalue)
#shadeentry['values']=("A1","A2","A3","A3.5","A4","B1","B2","B3","B4","C1","C2","C3","C4","D2","D3","D4")
#shadeentry.current()
#shadeentry = Entry(root, textvariable=shadevalue)
incisalentry =ttk.Combobox(root,width=6,textvariable=incisalvalue)
incisalentry['values']=("A1","A2","A3","A3.5","A4","B1","B2","B3","B4","C1","C2","C3","C4","D2","D3","D4")
incisalentry.current()
middleentry =ttk.Combobox(root,width=6,textvariable=middlevalue)
middleentry['values']=("A1","A2","A3","A3.5","A4","B1","B2","B3","B4","C1","C2","C3","C4","D2","D3","D4")
middleentry.current()
cervicalentry =ttk.Combobox(root,width=6,textvariable=cervicalvalue)
cervicalentry['values']=("A1","A2","A3","A3.5","A4","B1","B2","B3","B4","C1","C2","C3","C4","D2","D3","D4")
cervicalentry.current()
# Packing the Entries
labnameentry.grid(row=1, column=1,padx=5,pady=5)
patientnameentry.grid(row=1, column=3,sticky=tk.W,padx=5,pady=5)
patientageentry.grid(row=2, column=3,sticky=tk.W,padx=5,pady=5)
patientsexentry.grid(row=3, column=3,sticky=tk.W,padx=5,pady=5)
DateEntry.grid(row=5,column=3,sticky=tk.W,padx=5,pady=5)
#orderdateentry.grid(row=2, column=7)
workentry.grid(row=2, column=1,padx=5,pady=5)
toothnumberentry.grid(row=3, column=1,padx=5,pady=5)
materialentry.grid(row=4, column=1,padx=5,pady=5)
#shadeentry.grid(row=5, column=3,padx=5,pady=5)
incisalentry.grid(row=6, column=1,sticky=tk.W,padx=5,pady=5)
middleentry.grid(row=7, column=1,sticky=tk.W,padx=5,pady=5)
cervicalentry.grid(row=8, column=1,sticky=tk.W,padx=5,pady=5)
#Checkbox & Packing it
labservice = Checkbutton(text="Want metal coping trial",bg="light blue", variable = labservicevalue)
labservice.grid(row=9, column=2,sticky=tk.W)
toothreduction = Checkbutton(text="Do opposite tooth reduction",bg="light blue", variable = toothreductionvalue)
toothreduction.grid(row=11, column=2,sticky=tk.W)
reductioncoping = Checkbutton(text="Make reduction coping",bg="light blue", variable = reductioncopingvalue)
reductioncoping.grid(row=12, column=2,sticky=tk.W)
sendback = Checkbutton(text="Send the Case Back for correction",bg="light blue", variable = sendbackvalue)
sendback.grid(row=13, column=2,sticky=tk.W)
#Button & packing it and assigning it a command
Button(text=" submit ", command=getvals).grid(row=15, column=2)
root.mainloop()
Posts: 6,804
Threads: 20
Joined: Feb 2020
Aug-12-2021, 11:00 PM
(This post was last modified: Aug-12-2021, 11:00 PM by deanhystad.)
Using DateEntry as a variable name is a bad idea (line 100: DateEntry=cal). DateEntry is now an instance of the class tkcalendar.DateEntry instead of the class tkcalendar.DateEntry. You cannot make any more DateEntry objects ever again after this assignment. Maybe not a big problem in this case, but a potential source of confusion in the future and a big old flashing neon sign that says "I have no idea what I am doing!". Just use the variable "cal" when referencing the DateEntry object created in line 16.
Where do you think you are printing the selected date to the console. I cannot find where that would be happening.
Use the locale or date_pattern options to format how the date is displayed
https://tkcalendar.readthedocs.io/en/sta...r.html#doc < Notice readthedocs? Good advice. That's what I did.
If you want to print Yes, No instead of 1, 0, what's stopping you? Maybe you should read the docs. One solution is to configure the checkbox to use different values.
https://www.tutorialspoint.com/python/tk...button.htm
Another solution is to have the print statement print Yes or No instead of 1 or 0. There are lots of ways you can accomplish that. For example:
print(('No', 'Yes')[checkboxVar.get()])
|