试图拥有与第一帧到第二帧相同的标签项.Tkinter



尝试使用与第一帧到第二帧相同的标签条目。我尝试将第二个标签添加到我的函数中,但是,它根本没有注册为标签。试图找出如何保存标签条目。我不确定是否应该将它保存为一个变量,然后显示它,或者只是在两个帧中显示相同的标签。

import tkinter as tk 
import tkinter.messagebox as box
import csv
from tkinter import *
window = tk.Tk()

window.state('zoomed')
window.title('freshta otdering system')
def show_frame(fram):
fram.tkraise()

frame2 = tk.Frame(window)
frame3 = tk.Frame(window)
for frame in (frame1, frame2, frame3):
frame.grid(row=0,column=0,sticky='nsew')

filepath = '/Users/adamcleaver/Desktop/ICT/SAT part 1 /orders.csv'
File = open(filepath)

reader = csv.reader(File)

Data = list (reader)

del(Data[0])
list_of_entries = []
for x in list(range(0,len(Data))):
list_of_entries.append(Data[x][0])
var = StringVar(value = list_of_entries)
listbox1 = Listbox(frame2, listvariable = var)
listbox1.place(x= 10, y = 220, height = 500, width = 200)

def update():


index = listbox1.curselection()[0]
Foodlabel3.config(text = Data[index][1]) and Foodlabel2.config(text = Data[index][1])
Drinkslabel3.config(text = Data[index][2]) and Drinkslabel2.config(text = Data[index][2])
Pricelabel3.config(text = Data[index][3]) and Pricelabel2.config(text = Data[index][3])
return None


#using update function within the button
button1 = tk.Button(frame2, text="Update", command=update, fg = "blue", bg='yellow')
button1.place(x=400, y=450, height = 75, width = 125)
button2 = tk.Button(frame2, text="continue", command= lambda:show_frame(frame3), fg = "blue", bg='yellow')
button2.place(x=500, y=450, height = 75, width = 125)
Foodlabel = Label(frame2, text="Food", font=('Arial',20,'bold'),bg = '#F0EAD6').place(x= 295, y= 200)
Drinkslabel = Label(frame2, text="Drinks",font=('Arial',20,'bold'),bg = '#F0EAD6').place(x= 295, y= 300)
Pricelabel = Label(frame2, text="Total price ($)",font=('Arial',20,'bold'),bg = '#F0EAD6').place(x= 275, y=400)

Foodlabel2 = Label(frame2, text="",font=('Arial',20),bg = '#F0EAD6')
Foodlabel2.place(x= 425 , y= 200)

Drinkslabel2 = Label(frame2, text="",font=('Arial',20),bg = '#F0EAD6')
Drinkslabel2.place(x= 425, y= 300)

Pricelabel2 = Label(frame2, text="",font=('Arial',20),bg = '#F0EAD6' )
Pricelabel2.place(x=425, y= 400)

#label for login 
tk.Label(frame2, text = 'Ordering' ,font=('Arial',36), fg = 'red', bg = '#F0EAD6' ).place(x=0, y=125)
tk.Label(frame2, text = 'Your order :' ,font=('Arial',36), bg = '#F0EAD6' ).place(x= 320, y=125)

#==================Frame 3 code ========================================
#label for login 
tk.Label(frame2, text = 'Ordering' ,font=('Arial',36), fg = 'red', bg = '#F0EAD6' ).place(x=0, y=125)
Foodlabel3 = Label(frame3, text="",font=('Arial',20),bg = '#F0EAD6')
Foodlabel3.place(x= 425 , y= 200)

Drinkslabel3 = Label(frame3, text="",font=('Arial',20),bg = '#F0EAD6')
Drinkslabel3.place(x= 425, y= 300)

Pricelabel3 = Label(frame3, text="",font=('Arial',20),bg = '#F0EAD6' )
Pricelabel3.place(x=425, y= 400)

frame3_btn = tk.Button(frame3, text='Enter',command=lambda:show_frame(frame1))
frame3_btn.pack(fill='x',ipady=15)
show_frame(frame1)
window.mainloop()

这不是您使用and的方式。你需要:

def update():
index = listbox1.curselection()[0]
Foodlabel3.config(text = Data[index][1])
Foodlabel2.config(text = Data[index][1])
Drinkslabel3.config(text = Data[index][2])
Drinkslabel2.config(text = Data[index][2])
Pricelabel3.config(text = Data[index][3])
Pricelabel2.config(text = Data[index][3])

相关内容

  • 没有找到相关文章

最新更新