我对编码还比较陌生。我正在尝试创建一个程序,您可以在其中将信息输入到有关一本书的框中。可以提交此信息并将其保存到txt文件中,然后清除。我希望您也可以通过单击搜索按钮来搜索书籍,在其中可以通过键入书籍的名称来搜索书籍。条件标签旨在使下拉菜单带有选项,但我无法设置其格式。由于我是代码新手,因此我的代码会有很多问题,但是如果能在此方面获得帮助,将不胜感激。谢谢。
from tkinter import *
bookshopFile=open("bookshop.txt","a")
root=Tk()
root.geometry("1000x600")
root.title("Book Shop")
root.resizable(False,False)
root.configure(bg="#d9e7fc")
frame_heading=Frame(root)
frame_heading.grid(row=0,column=0,columnspan=2, padx=100,pady=5)
frame_entry=Frame(root)
frame_entry.grid(row=1,column=0,columnspan=2, padx=25,pady=10)
def Submit():
Book_Title_get=Book_Title.get()
Author_get=Author.get()
Genre_get=Genre.get()
YoP=Year_of_Publication.get()
Condition_get=Condition.get()
bookshopFile.write(Book_Title_get+","+Author_get+",
"+Genre_get+","+YoP+","+Condition_get+"\n")
bookshopFile.close()
def Clear():
Book_Title.delete(0,END)
Author.delete(0,END)
Genre.delete(0,END)
Year_of_Publication.delete(0,END)
Condition.delete(0,END)
def Search():
Label(frame_entry,text="Name of Book").grid(row=6,column=0,
padx=10,pady=0)
Name_of_Book=Entry(frame_entry,width=20,bg="white")
Name_of_Book.grid(row=6,column=1, padx=10,pady=0)
Label(frame_heading, text= "Book Shop").grid(row=0,column=0,
padx=0,pady=0)
Label(frame_entry,text="Book Title").grid(row=1,column=0,
padx=10,pady=0)
Label(frame_entry,text="Author").grid(row=2,column=0, padx=10,pady=0)
Label(frame_entry,text="Genre").grid(row=3,column=0, padx=10,pady=0)
Label(frame_entry,text="Year of Publication").grid(row=4,column=0,
padx=10,pady=0)
Label(frame_entry,text="Condition").grid(row=5,column=0,
padx=10,pady=0)
Book_Title=Entry(frame_entry,width=20,bg="white")
Book_Title.grid(row=1,column=1, padx=10,pady=0)
Author=Entry(frame_entry,width=20,bg="white")
Author.grid(row=2,column=1, padx=10,pady=0)
Genre=Entry(frame_entry,width=20,bg="white")
Genre.grid(row=3,column=1, padx=10,pady=0)
Year_of_Publication=Entry(frame_entry,width=20,bg="white")
Year_of_Publication.grid(row=4,column=1, padx=10,pady=0)
choices = ['Used','New','Other']
tkvar = StringVar(root)
tkvar.set(choices[0])
C_Popup = OptionMenu(root, tkvar, *choices)
C_Popup.grid(row=5, column=1)
root.mainloop()
Condition=Entry(C_Popup,width=20)
Condition.C_Popup(row=5,column=1)
button1=Button(root,text="Submit",width=7,command=Submit)
button1.grid(row=8,column=0)
button2=Button(root,text="Clear",width=7,command=Clear)
button2.grid(row=9,column=0)
button3=Button(root,text="Search",width=7,command=Search)
button3.grid(row=10,column=0)