这是我得到的错误。
Tkinter回调中的异常 Traceback(最近一次调用最后一次): 文件" C:\ Users \ kl_nnanna \ AppData \ Local \ Programs \ Python \ Python35-32 \ lib \ tkinter__init __。py",第1550行,调用 return self.func(* args) 文件" C:/Users/kl_nnanna/PycharmProjects/future_value/Idcalls.py",第71行,在calc_price中 radio = self.radio_var.get() 文件" C:\ Users \ kl_nnanna \ AppData \ Local \ Programs \ Python \ Python35-32 \ lib \ tkinter__init __。py",第355行,in get return self._tk.getint(self._tk.globalgetvar(self._name)) TypeError:getint()参数必须是str,而不是float
这是我的代码。
导入tkinter import tkinter.messagebox
类LongCallsGUI: def init (个体经营): #创建主窗口。 self.main_window = tkinter.Tk()
# Create frames for the radio button and for button widgets.
self.top_frame = tkinter.Frame(self.main_window)
self.minute_frame = tkinter.Frame(self.main_window)
self.bottom_frame = tkinter.Frame(self.main_window)
# Create an IntVar object to use the radio buttons.
self.radio_var = tkinter.IntVar()
# Set the IntVar to 1.
self.radio_var.set(1)
# Create the RadioButton widgets in the top frame.
self.rb1 = tkinter.Radiobutton(self.top_frame, \
text ='Daytime: $0.07', variable=self.radio_var,\
value= 0.07)
self.rb2 = tkinter.Radiobutton(self.top_frame, \
text ='Evening: $0.12', variable=self.radio_var,\
value= 0.12)
self.rb3 = tkinter.Radiobutton(self.top_frame, \
text ='Off-Peak: $0.05', variable=self.radio_var,\
value= 0.05)
# Pack the RadioButtons
self.rb1.pack()
self.rb2.pack()
self.rb3.pack()
# Create and pack the widgets for minutes.
self.minute_label = tkinter.Label(self.minute_frame, \
text='Enter the minutes of call:')
self.minute_entry = tkinter.Entry(self.minute_frame, \
width=10)
self.minute_label.pack(side='left')
self.minute_entry.pack(side='left')
# Create an OK button and Quit button.
self.calc_button = tkinter.Button(self.bottom_frame, \
text='Price', command=self.calc_price)
self.quit_button = tkinter.Button(self.bottom_frame, \
text='Quit', command=self.main_window.destroy)
# Pack the buttons.
self.calc_button.pack(side='left')
self.quit_button.pack(side='left')
# Pack the frames.
self.top_frame.pack()
self.minute_frame.pack()
self.bottom_frame.pack()
# Start the mainloop
tkinter.mainloop()
def calc_price(self):
# Get the value entered by user.
radio = self.radio_var.get()
minute = float(self.minute_entry.get())
price = radio * minute
tkinter.messagebox.showinfo('Price', 'You total is' + str(self.radio_var.get()) +\
str(price))
my_gui = LongCallsGUI()