Addimg Tkinter中的搜索和显示按钮

时间:2019-07-12 08:48:31

标签: python-3.x tkinter

我是编程新手,正在自学。我遇到了这个问题。.我无法添加一个命令来搜索我的delivery.txt文件中的数据。我需要帮助,以便能够查看在同一tkinter窗口中搜索到的数据。

from tkinter import *
import tkinter.messagebox
def save_data():
    try:
        fileD = open("deliveries.txt", "a")
        fileD.write("TYPE:\n")
        fileD.write("%s\n" % TYPE.get())
        fileD.write("Description:\n")
        fileD.write("%s\n" % description.get())
        fileD.write("Address:\n")
        fileD.write("%s\n" % address.get("1.0", END))
        TYPE.set("")
        description.delete(0, END)
        description.delete(0, END)
        address.delete("1.0", END)
     except Exception as ex:
        tkinter.messagebox.showerror("Error!", 
            "Can't.write to the file\n %s" % ex)
app = Tk()
app.title('DATA STORE AND SEARCH ENGINE')
Label(app, text = "TYPE:").pack()

TYPE = StringVar()
TYPE.set(None)
TYPE = StringVar()
TYPE.set(None)
TYPE = StringVar()
TYPE.set(None)
OptionMenu(app, TYPE, "Title deeds", "Cause 
        lists", "Case files").pack()

Label(app, text = "DESCRIPTION").pack()
description = Entry(app)
description.pack()

Label(app, text = "SERIAL NUMBER").pack()
SERIAL_NUMBER = Entry(app)
SERIAL_NUMBER.pack()

Label(app, text = "Address:").pack()
address = Text(app)
address.pack()
Button(app, text = "Save", command = 
save_data).pack()

Label(app, text = "Search:").pack()
Search = Entry(app)
Search.pack()

Button(app,text = "SEARCH FILE DATA", 
command = lambda: msearch).pack()

def msearch_data():
    open_file = open(file, 'a') # Opens file.user.    
    chose
    print(open_file.read())                 # Displays.    
    contents in console
    open_file.close()                       # Closes text file
     mSearch = Button.    
    (app,text='Search',bg='white',font='Cambria', 
    command = lambda: msearch())

 app.mainloop()

0 个答案:

没有答案