材料计算器:将材料数量除以单位成本
我正在尝试创建一个 GUI,允许用户计算 3D 打印作业所用材料的成本。
用户应选择打印机和材料,然后输入使用的材料量(从打印机软件手动获取)。然后,GUI 应根据材料和用户输入的金额显示材料成本。
目前,“材料成本”(£) 标题下方没有显示任何内容,因为我无法将它们链接起来。
下面是我的代码:
import tkinter as tk
from tkinter import ttk
app = tk.Tk()
app.geometry("500x250")
app.title("AM Materials Cost")
app.maxsize(500,250)
app.minsize(500,250)
# title
Label(text="Additive Manufacturing \\nMaterial Cost Calculator", fg="black", width="20", height="2", font=("Calibri", 16)).place(x=200, y=10)
# printer text line
Label(text="Select Printer", fg="black", width="20", height="2", font=("Calibri", 11)).place(x=50, y=75)
#material text line
Label(text="Select Material", fg="black", width="20", height="2", font=("Calibri", 11)).place(x=290, y=75)
def clear_text():
text.delete(0, END)
def pick_material(e):
if printer_combo.get() == "Fortus":
material_combo.config(value=fortus_materials)
if printer_combo.get() == "Markforged":
material_combo.config(value=markforged_materials)
if printer_combo.get() == "Polyjet":
material_combo.config(value=polyjet_materials)
#create list of printers
printers = [
"Fortus",
"Markforged",
"Polyjet"
]
#create list of printers and associated materials
fortus_materials = [
"ASA",
"ABS-ESD7",
"PC-ABS",
"Ultem"
]
markforged_materials = [
"Carbon Fiber",
"Onyx"
]
polyjet_materials = [
"TangoBlack",
"VeroClear",
"VeroWhite",
"Digital ABS",
]
#material price per unit - amend value within " "
asa_ppu = ["0.17"]
absesd7_ppu = ["0.19"]
pc_ppu = ["0.19"]
ultem_ppu= ["0.33"]
carbonfiber_ppu = ["1.00"]
onyx_ppu = ["0.19"]
tangoblack_ppu = ["0.25"]
veroclear_ppu = ["0.28"]
verowhite_ppu = ["0.18"]
digitalabs_ppu = ["0.30"]
#create dropdown box
printer_combo = ttk.Combobox(app, value=printers)
printer_combo.place(x=60, y=110)
#material combobox
material_combo = ttk.Combobox(app, value=[""])
material_combo.place(x=300, y=110)
#material amount text line
Label(text="Enter Material Amount", fg="black", width="20", height="1", font=("Calibri", 11)).place(x=50, y=145)
#material cost text line
Label(text="Cost of Material (£):", fg="black", width="20", height="1", font=("Calibri", 11)).place(x=290, y=145)
#entry box for amount
e = Entry(app,justify="center")
e.place(x=70, y=175)
e.delete(0,'end')
#material cost output
def myClick():
myLabel = Label(app, text='', height="1", font=("Calibri", 20))
myLabel.place(x=340, y=163)
#calculate button
myButton = Button(app, text="Calculate", command=myClick)
myButton.place(x=220, y=170)
#close button
exit_button = Button(app, text="Close", command=app.destroy)
exit_button.place(x=450, y=215)
I am trying to create a GUI which allows the user to calculate the cost of material used on a 3D print job.
The user should select the printer and the material, then enter the amount of material used (manually taken from the printer software). The GUI should then display the cost of material based on the material and the amount entered by the user.
At the moment, nothing appears below the Cost pf material(£) heading as I can't link these up.
Below is my code:
import tkinter as tk
from tkinter import ttk
app = tk.Tk()
app.geometry("500x250")
app.title("AM Materials Cost")
app.maxsize(500,250)
app.minsize(500,250)
# title
Label(text="Additive Manufacturing \\nMaterial Cost Calculator", fg="black", width="20", height="2", font=("Calibri", 16)).place(x=200, y=10)
# printer text line
Label(text="Select Printer", fg="black", width="20", height="2", font=("Calibri", 11)).place(x=50, y=75)
#material text line
Label(text="Select Material", fg="black", width="20", height="2", font=("Calibri", 11)).place(x=290, y=75)
def clear_text():
text.delete(0, END)
def pick_material(e):
if printer_combo.get() == "Fortus":
material_combo.config(value=fortus_materials)
if printer_combo.get() == "Markforged":
material_combo.config(value=markforged_materials)
if printer_combo.get() == "Polyjet":
material_combo.config(value=polyjet_materials)
#create list of printers
printers = [
"Fortus",
"Markforged",
"Polyjet"
]
#create list of printers and associated materials
fortus_materials = [
"ASA",
"ABS-ESD7",
"PC-ABS",
"Ultem"
]
markforged_materials = [
"Carbon Fiber",
"Onyx"
]
polyjet_materials = [
"TangoBlack",
"VeroClear",
"VeroWhite",
"Digital ABS",
]
#material price per unit - amend value within " "
asa_ppu = ["0.17"]
absesd7_ppu = ["0.19"]
pc_ppu = ["0.19"]
ultem_ppu= ["0.33"]
carbonfiber_ppu = ["1.00"]
onyx_ppu = ["0.19"]
tangoblack_ppu = ["0.25"]
veroclear_ppu = ["0.28"]
verowhite_ppu = ["0.18"]
digitalabs_ppu = ["0.30"]
#create dropdown box
printer_combo = ttk.Combobox(app, value=printers)
printer_combo.place(x=60, y=110)
#material combobox
material_combo = ttk.Combobox(app, value=[""])
material_combo.place(x=300, y=110)
#material amount text line
Label(text="Enter Material Amount", fg="black", width="20", height="1", font=("Calibri", 11)).place(x=50, y=145)
#material cost text line
Label(text="Cost of Material (£):", fg="black", width="20", height="1", font=("Calibri", 11)).place(x=290, y=145)
#entry box for amount
e = Entry(app,justify="center")
e.place(x=70, y=175)
e.delete(0,'end')
#material cost output
def myClick():
myLabel = Label(app, text='', height="1", font=("Calibri", 20))
myLabel.place(x=340, y=163)
#calculate button
myButton = Button(app, text="Calculate", command=myClick)
myButton.place(x=220, y=170)
#close button
exit_button = Button(app, text="Close", command=app.destroy)
exit_button.place(x=450, y=215)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论