我真的需要这方面的帮助,对python和tkinter来说有点新手,而且我试图用它来创造一些东西。当我尝试通过输入框插入数据时。这是我得到的错误
Tkinter回调中的异常 Traceback(最近一次调用最后一次): 档案
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/tkinter/__init__.py", line 1699, in __call__
return self.func(*args)
File "/Users/.../Documents/atom-python.projects/billingsystem.py", line 217, in <lambda>
enterbutton = ttk.Button(self, text='Enter', command=lambda:(insert(self)))
File "/Users/.../Documents/atom-python.projects/billingsystem.py", line 45, in insert
item_i = self.entryitem.get()
AttributeError: 'inventrylog' object has no attribute 'entryitem'
这是我的代码,
def Database(self):
global conn, cursor
conn = sqlite3.connect("billingsystem.db")
cursor = conn.cursor()
cursor.execute("CREATE TABLE IF NOT EXISTS product (id INTEGER PRIMARY KEY, item TEXT, price TEXT)")
#cursor.execute("SELECT * FROM `product` WHERE `item` = '?' AND `price` = '?'")
conn.commit()
def insert(self):
item_i = self.entryitem.get()
price_i = self.pentry.get(self)
conn = sqlite3.connect('billingsystem.db')
with conn:
cursor = conn.cursor()
cursor.execute('INSERT INTO product(item, price ) VALUES(?,?)', (item_i, price_i))
lis = cursor.execute('SELECT * FROM product')
class billingsystem(tk.Tk):
def __init__(self, *args, **kwargs): # initialize class
tk.Tk.__init__(self, *args, **kwargs) # initialize tkinter
tk.Tk.iconbitmap(self, default='')
tk.Tk.wm_title(self, 'DEPARTMENTAL BILLING SYSTEM')
container = tk.Frame(self) # call frame
container.pack(side='top', fill='both', expand=True) # pack frame
container.grid_rowconfigure(0, weight=1) # configure frame row
container.grid_columnconfigure(0, weight=1) # configure frame column
self.frames = {} # dictionary
for F in (StartPage,Record,inventory,inventrylog):
frame = F (container, self) # defining startframe page
self.frames[F] = frame # put frame in ditionary
frame.grid(row=0, column=0, sticky='nsew') # pack frame
self.show_frame(StartPage) # show startpage frame
def show_frame(self, cont): #defining show_frame functiion
frame = self.frames[cont] #putting show_frame function in a dict with key [cont]
frame.tkraise() #raising frames
# menubar
menubar = tk.Menu(self)
inventory = tk.Menu(menubar, tearoff=0)
inventory.add_command(label='Inventory', command=lambda:self.show_frame(inventrylog))
inventory.add_separator()
inventory.add_command(label='Exit', command=quit)
menubar.add_cascade(label='Inventory Log', menu=inventory)
tk.Tk.config(self, menu=menubar)
class StartPage(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
label1 = tk.Label(self, text=('Date:',time.strftime('%A %m/%d/%y',time.localtime())), font=LARGE_FONT)
label1.place(x=30,y=30)
clock = tk.Label(self, text=time_string, font=LARGE_FONT)
clock.place(x=240, y=30)
def tick():
global time1
# get the current local time from the PC
time2 = time.strftime('%H:%M:%S')
# if time string has changed, update it
if time2 != time1:
time1 = time2
clock.config(text=('Time:',time2))
# calls itself every 200 milliseconds
# to update the time display as needed
# could use >200 ms, but display gets jerky
clock.after(200, tick)
tick()
label3 = tk.Label(self, text='Item', font=LARGE_FONT)
label3.place(x=30,y=100)
entry_1 = Entry(self)
entry_1.place(x=30,y=120)
label4 = tk.Label(self, text='Quantity', font=LARGE_FONT)
label4.place(x=30,y=170)
entry_2 = Entry(self)
entry_2.place(x=30,y=190)
calculatebutton = ttk.Button(self, text='Enter')
calculatebutton.place(x=30, y=250)
button4 = ttk.Button(self, text='TOTAL')
#command=lambda: controller.show_frame(Record))
button4.place(x=30,y=390)
#entry_3 = Entry(self)
#entry_3.place(x=30,y=260)
#cmb = tk.Listbox(self)
#cmb.place(x=250,y=120)
chat1 = ttk.Treeview(self, height=15, columns=('Quantity','Price'), selectmode="extended")
chat1.heading('#0', text='Item', anchor=tk.CENTER)
chat1.heading('#1', text='Quntity', anchor=tk.CENTER)
chat1.heading('#2', text='Price', anchor=tk.CENTER)
chat1.column('#1', stretch=tk.YES, minwidth=50, width=100)
chat1.column('#2', stretch=tk.YES, minwidth=50, width=100)
chat1.column('#0', stretch=tk.YES, minwidth=50, width=100)
chat1.place(x=250,y=120)
label5 = tk.Label(self, text='Total:', font=LARGE_FONT)
label5.place(x=250, y=440)
button1 = ttk.Button(self, text='VIEW RECORDS', command=lambda: controller.show_frame(Record))
button1.place(x=30,y=440) # adding buttons to frame or page
class Record(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
label1 = tk.Label(self,text=('Date:',time.strftime('%A %m/%d/%y',time.localtime())), font=LARGE_FONT)
label1.place(x=30, y=30)
#cmb = tk.Listbox(self)
#cmb.place(x=30, y=100)
chat2 = ttk.Treeview(self, height=15, columns=('Quantity', 'Price'), selectmode="extended")
chat2.heading('#0', text='Item', anchor=tk.CENTER)
chat2.heading('#1', text='Quntity', anchor=tk.CENTER)
chat2.heading('#2', text='Price', anchor=tk.CENTER)
chat2.column('#1', stretch=tk.YES, minwidth=50, width=160)
chat2.column('#2', stretch=tk.YES, minwidth=50, width=160)
chat2.column('#0', stretch=tk.YES, minwidth=50, width=160)
chat2.place(x=50, y=90)
button2 = ttk.Button(self, text='BACK TO MAIN', command=lambda: controller.show_frame(StartPage))
button2.place(x=30, y=440) # adding buttons to frame or page
button3 = ttk.Button(self, text='EXIT', command=quit)
button3.place(x=400,y=440)
class inventrylog(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
itemlabel = tk.Label(self, text='Item', font=LARGE_FONT)
itemlabel.place(x=30, y=100)
entryitem = Entry(self)
entryitem.place(x=30, y=120)
pricelabel = tk.Label(self, text='price', font=LARGE_FONT)
pricelabel.place(x=30, y=170)
pentry = Entry(self)
pentry.place(x=30, y=190)
inventorychat = ttk.Treeview(self, height=15, columns=('Quantity', 'Price'), selectmode="extended")
inventorychat.heading('#0', text='Item', anchor=tk.CENTER)
inventorychat.heading('#1', text='Quntity', anchor=tk.CENTER)
inventorychat.heading('#2', text='Price', anchor=tk.CENTER)
inventorychat.column('#1', stretch=tk.YES, minwidth=50, width=100)
inventorychat.column('#2', stretch=tk.YES, minwidth=50, width=100)
inventorychat.column('#0', stretch=tk.YES, minwidth=50, width=100)
inventorychat.place(x=250, y=120)
enterbutton = ttk.Button(self, text='Enter', command=lambda:(insert(self)))
#popupmsg('Not Supported Just Yet!'))
enterbutton.place(x=30, y=300) # adding buttons to frame or page
需要我能得到的所有帮助。感谢