【发布时间】:2019-06-11 20:38:46
【问题描述】:
我想解决问题或使用其他方法输入此命令行
from tkinter import *
from tkinter import ttk
from tkinter import messagebox
root = Tk()
ent = ttk.Entry(root, width=40)
ent.pack()
ent1 = ttk.Entry(root, width=40)
ent1.pack()
bu = ttk.Button(root, text="click")
bu.pack()
i = ent.get()
sentence = i
sentence.replace(" ", "")
def buclick():
if i == i():
i()
else:
messagebox.showinfo("Error", "There is no product with this name")
bu.config(command=buclick)
print("Product" + " " + "quantity" + " " + "Price per one" + " " + "Total")
class Product:
index = 0
item = ''
quantity = 0
price_per_once = 0
total = 0
def __init__(self, item, quantity, price_per_once, total):
self.item = item
self.quantity = quantity
self.price_per_once = price_per_once
self.total = total
def return_information(self):
return self.item + " " + str(self.quantity) + " " + str(
self.price_per_once) + " " + str(self.sum)
def print_information(self):
print(self.return_information())
def ic5501():
item = "ic 550"
result = int(ent1.get())
quantity = result
price_per_once = 15
total = (15 * result)
ic550 = Product(item, quantity, price_per_once, total)
ic550.return_information()
ic550.print_information()
def ic5502():
item = "ic 5502"
result = int(ent1.get())
quantity = result
price_per_once = 20
total = (20 * result)
ic550 = Product(item, quantity, price_per_once, total)
ic550.return_information()
ic550.print_information()
root.mainloop()
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\Ahmed Rabea Smaha\AppData\Local\Programs\Python\Python35-32\lib\tkinter\__init__.py", line 1549, in __call__
return self.func(*args)
File "C:/Users/Ahmed Rabea Smaha/PycharmProjects/untitled/untitled.py", line 22, in buclick
if i == i():
TypeError: 'str' object is not callable
【问题讨论】:
-
i 是一个字符串,当您尝试像
i()这样调用该字符串时,您会做什么? -
我怀疑
if i == i(): i()的预期行为是“如果字符串i与该程序中的函数同名,则调用该函数”。不幸的是,这样做比您当前的方法更复杂。 -
是的,我想要@Kevin 我怎么能用另一种简单的方法做到这一点
标签: python python-3.x