【发布时间】:2018-02-14 15:52:47
【问题描述】:
我正在使用带有 abd 类的 tkinter,我在添加产品时遇到了问题
class Add_Page():
def __init__(self, child):
self.child = child
child.title = "Ajouter"
self.l1=Label(child,text="Ajouter produit :",bg="blue").grid(row=0,columnspan=2)
self.l2=Label(child,text="Matricule").grid(row=1,column=0)
self.vlrm = StringVar()
self.en2 = Entry(child, textvariable=self.vlrm, width=30).grid(row=1,column=1)
self.l3=Label(child,text="Nom").grid(row=2,column=0)
self.vlrn = StringVar()
self.en3 = Entry(child, textvariable=self.vlrn, width=30).grid(row=2,column=1)
self.l4=Label(child,text="Prix").grid(row=3,column=0)
self.vlrp = IntVar()
self.en4 = Entry(child, textvariable=self.vlrp, width=30).grid(row=3,column=1)
self.b2=Button(child,text="Valider",command=self.add_p).grid(row=4,columnspan=2)
#Add product function
def add_p(self):
print(self.vlrm.get())
print(self.vlrp.get())
结果是一个空链和 0 我似乎没有发现问题,特别是我在用户类中使用了 get 方法并且它工作得很好 帮助
【问题讨论】:
-
请提供minimal reproducible example。为什么我们需要弄清楚你是如何使用这个类的?我对您的代码的猜测按预期工作。
-
对不起,我第一次在这里发帖,但我迷路了,不知道代码对我不起作用的问题是什么
-
这个问题不足以提供答案。该代码不可测试,因此您需要按照 Nae 提供的链接并相应地重写您的问题。
-
aah 这是我的其余代码,我把它放在评论中,因为他们一直在我的数据库中添加一个 emty 产品 ''' produit = Products(matricule_pro=mat,name_pro=nom,price_pro=pric) session.add(produit) session.commit() self.child.withdraw()'''
-
@Shaymae 您可以edit 提出您的问题,但您在上面输入的内容几乎不是minimal reproducible example 是。
标签: python python-3.x oop tkinter