私はあなたが次のコードで私を助けて、どこが間違っているのか教えてくれることを望んでいました. 私はPythonの経験があまりないので、助けていただければ幸いです! 私のコードは次のとおりです。
from Tkinter import *
import math
from math import *
import tkFont
import tkMessageBox
numberOfIngredients = {}
diameter = {}
class Application(Frame):
""" GUI application that creates a story based on user input. """
def __init__(self, master):
""" Initialize Frame. """
#Make size later master.geometry("485x280+5+10")
Frame.__init__(self, master)
self.grid()
self.create_widgets()
self.config(bg = "#a6b6cb")
def create_widgets(self):
""" Define the widgets and positioning within the frame. """
#Display the Title
Label(self, text = "Hamburger Calculator", font = ("Calibri", "25"), bg = "#a6b6cb", fg = "#17375e").grid(row = 0, column = 1, sticky = W)
#Instructions For Selecting Box
Label(self, text ="Select your extra ingredients:",
bg = "#a6b6cb").grid(row = 1, column =1, sticky = W)
#Button To Calculate
Button(self, text = "Calculate Cost", bg = "#92d050",
command = self.calculate,
font = ("Calibri", "12")).grid(row = 6, column = 1, sticky = SE)
#Button To Quit
Button(self, text = "Quit", bg = "#913c3a",
command = self.quit,
font = ("Calibri", "12")).grid(row = 7, column = 1,
sticky = SE)
#Radio Box For Patty Size
Label(self, text ="Hamburger Size:",
bg = "#a6b6cb").grid(row = 1, column = 0, sticky = W)
diameter = IntVar()
Radiobutton(self,
text = "10 cm",
bg = "#a6b6cb",
variable = diameter,
value = 10,
).grid(row = 3, column = 0, sticky =W)
Radiobutton(self,
text = "20 cm",
bg = "#a6b6cb",
variable = diameter,
value = 20,
).grid(row = 4, column = 0, sticky =W)
Radiobutton(self,
text = "35 cm",
bg = "#a6b6cb",
variable = diameter,
value = 35,
).grid(row = 5, column = 0, sticky =W)
#Check Box for Cheese
self.cheese = BooleanVar()
Checkbutton(self,
text="Cheese",
bg = "#a6b6cb",
variable = self.cheese,
onvalue="yes", offvalue="no"
).grid(row =3,
column = 1, sticky =W)
#Check Box for Mushrooms
self.mushroom = BooleanVar()
Checkbutton(self,
text="Mushrooms",
bg = "#a6b6cb",
variable = self.mushroom,
onvalue="yes", offvalue="no"
).grid(row =4,
column = 1, sticky =W)
#Check Box for Onions
self.onion = BooleanVar()
Checkbutton(self,
text="Onions",
bg = "#a6b6cb",
variable = self.onion,
onvalue="yes", offvalue="no"
).grid(row =5,
column = 1, sticky =W)
#Check Box for Extra Beefburger
self.beefburger = BooleanVar()
Checkbutton(self,
text="Extra Burger Patty",
bg = "#a6b6cb",
variable = self.beefburger,
onvalue="yes", offvalue="no"
).grid(row =6,
column = 1, sticky =W)
numberOfIngredients = 0
if self.cheese.get() == "yes":
numberOfIngredients + 1
if self.mushroom.get() == "yes":
numberOfIngredients + 1
if self.onion.get() == "yes":
numberOfIngredients + 1
if self.beefburger.get() == "yes":
numberOfIngredients + 1
def calculate(self):
#Constants and Variables
fixedCost = 3.75
baseCost = 1.55
extraCost = 1.25
global numberOfIngredients
global diameter
#Formulas
area = (pi * sqrt(int(diameter) / 100) ) / 4
cost = fixedCost + (baseCost * area) + (numberOfIngredients * extraCost)
totalCost = 1.5 * cost
#Message Box
tkMessageBox.showinfo(
title="Total Cost",
message="The total cost of the hamburger is $" + str(diameter))
#Main
root = Tk()
root.title("Hamburger Calculator")
app = Application(root)
root.mainloop()
root.destroy()
現時点で発生するエラーは次のとおりです。
Tkinter コールバック トレースバックの例外 (最新の呼び出しが最後): ファイル "C:\Python27\lib\lib-tk\Tkinter.py"、1410 行、呼び出しで return self.func(*args) ファイル "C:\Users\ Matt Sharp\Desktop\Assessment For Hamburgers v2tester.py"、131 行目、calculate area = (pi * sqrt(int(diameter) / 100) ) / 4 TypeError: int() 引数は文字列または数値でなければなりません。 「口述」
このエラーだけでなく、diameter と numberOfIngredients が機能していないこともわかっています。