根据输入设置变量

时间:2019-03-18 21:38:38

标签: python python-3.x tkinter tkinter-entry

我希望在tkinter中制作一个主题公园售票程序,我已经在python 3中实现了,但是我正在尝试将其实施到tkinter中。但是,我不确定如何基于tkinter中的用户输入来设置变量。我希望程序要求用户输入一个整数,表示他们想购买的门票数量,这将导致根据其输入计算出的费用。

class PageAdultTickets(tk.Frame):
    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent, bg="red")
        self.controller = controller
        label1 = tk.Label(self, text="------------- Welcome to Fantasialand Ticket Station ------------", fg="Blue", font=controller.title_font)
        label1.pack(side="top", fill="x", pady=10)

        label2 = tk.Label(self, text=f"The price of 1 adult ticket is £{adultTicket:0.2f}", fg="steelblue", bg="yellow", font=controller.title_font)
        label2.pack(side="top", fill="x", pady=5)
        button1 = tk.Button(self, text="Go to Main Menu",
                           command=lambda: controller.show_frame("MainMenu"))
        button1.pack(side="right")

        v = tk.IntVar()
        amAdultTickets = tk.Entry(self, textvariable=v)
        amAdultTickets.pack(side="bottom")
        s = v.get()

换句话说,如果你们可以帮助我如何使用该行中的唯一购买ID来读取csv文件中的行,我将非常感激:

def searchingForFile():
  iUniqueID = int(input("What is the Unique ID of the past purchase?")
  with open("Purchases.csv", mode="rt", encoding='ascii') as f:
     spamreader = csv.reader(f, delimiter=' ', quotechar='|')
     for row in spamreader :
        print(' '.join(row))

0 个答案:

没有答案