長距離の特定の時刻に通話料金を表示するラジオボタンを使用してプログラムを作成することが任されています。昼間は毎分0.07、夕方は毎分0.12で、ピークは毎分0.05です。何らかの理由で、話した分の量を特定の時間帯の料金で乗算し、答えを出力する方法を理解できないようです。Python Tkinter長距離通話
これは、これまでの私のコードであり、私は$ 0出力を取得しています:
import tkinter
import tkinter.messagebox
def main():
my_gui = TelephoneRatesGUI()
class TelephoneRatesGUI():
def __init__(self):
self.main_window = tkinter.Tk()
#create 3 frames
self.top_frame = tkinter.Frame(self.main_window)
self.mid_frame = tkinter.Frame(self.main_window)
self.bottom_frame = tkinter.Frame(self.main_window)
#create an intvar object
self.radio_var = tkinter.IntVar()
#set the intVar object to 1.
self.radio_var.set(1)
#create the radiobutton widgets in the top_frame
self.rb1 = tkinter.Radiobutton(self.top_frame,
text='Daytime(6:00am - 5:59pm)',
variable=self.radio_var,
value=.07)
self.rb2 = tkinter.Radiobutton(self.top_frame,
text='Evening(6:00pm - 11:59pm)',
variable=self.radio_var,
value=.12)
self.rb3 = tkinter.Radiobutton(self.top_frame,
text='Off-Peak(12:00am - 5:59am)',
variable=self.radio_var,
value=.05)
#pack the radiobuttons
self.rb1.pack()
self.rb2.pack()
self.rb3.pack()
#create widgets for the middle frame
self.prompt_label = tkinter.Label(self.mid_frame,
text='Enter the number of minutes:')
self.num_min = tkinter.Entry(self.mid_frame,
width=10)
#pack the mid frame's widgets
self.prompt_label.pack(side='left')
self.num_min.pack(side='left')
#create a display charges button and a quit button
self.dis_button = tkinter.Button(self.bottom_frame,
text='Display Charges',
command=self.show_charges)
self.quit_button = tkinter.Button(self.bottom_frame,
text='Quit',
command=self.main_window.destroy)
#pack the buttons
self.dis_button.pack(side='left')
self.quit_button.pack(side='left')
#pack the frames
self.top_frame.pack()
self.mid_frame.pack()
self.bottom_frame.pack()
#start the mainloop
tkinter.mainloop()
def show_charges(self):
charges = float(self.radio_var.get())
minutes = float(self.num_min.get())
tkinter.messagebox.showinfo('Total Charges', 'Your total charges = $' +
format(float(charges*minutes)))
main()
あなたはどんな問題を抱えていますか? 「なぜこのコードが動作しないのか」と尋ねるのは、ここでは話題にはなりません。あなたはどんな特定の問題を抱えていますか? UIから値を取得するには?計算していますか?結果をUIに戻しますか?他に何か?あなたは 'show_charges'で' charges'と 'minutes'があなたの期待するものであることを確認しましたか? –
出力が正しくありません。それはちょうど$ 0です。あなたがプログラムに入力した分の量に料金の設定値を掛けなければなりません。 – Classicalclown