从功能获取值的问题

问题描述 投票:0回答:1

当我在函数结构中打印它们时,我无法从函数nbarticle中检索值

我不知道是否像我那样做是最好的方法,而in能否在我的函数中做到这一点?

class  second_frame():
"""docstring for  second_frame"""
def __init__(self):
    self.nombre_article = 1

def facture(self):
    window2 = Tk()
    width_value=window.winfo_screenwidth()
    height_value=window.winfo_screenheight()
    window2.geometry("%dx%d+0+0" % (width_value, height_value))
    window.destroy()
    window2.title("Veleos     |     Facture")
    tkinter.Radiobutton(window2, text="Professionnel", value=1).grid(row=1, column=1)
    tkinter.Radiobutton(window2, text="Particulier", value=2).grid(row=1, column=2)

    tkinter.Label(window2, text="Nom : ").grid(row=2, column=1)
    nom = tkinter.Entry(window2).grid(row=3, column=1)

    tkinter.Label(window2, text="Prénom : ").grid(row=2, column=2)
    prenom = tkinter.Entry(window2).grid(row=3, column=2)

    tkinter.Label(window2, text="Adresse : ").grid(row=4, column=1 , columnspan=2)
    adresse = tkinter.Entry(window2).grid(row=5, column=1, columnspan=2)

    tkinter.Label(window2, text="Ville : ").grid(row=6, column=1)
    ville = tkinter.Entry(window2).grid(row=7, column=1)

    tkinter.Label(window2, text="Code Postal : ").grid(row=6, column=2)
    cp = tkinter.Entry(window2).grid(row=7, column=2)

    tkinter.Label(window2, text="Nombre d'article : ").grid(row=8, column=1, columnspan=2)
    OptionList = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"] 
    var = StringVar(window2)
    var.set(OptionList[0])
    drop = tkinter.OptionMenu(window2, var, *OptionList, command=second_frame.nbarticle).grid(row=9, column=1, columnspan=2)

    print(self.nombre_article)
    window2.mainloop()

def nbarticle(self, nombreArticle):
    self.nombre_article = nombreArticle
    return self.nombre_article
python-3.x tkinter optionmenu
1个回答
0
投票

我为正在寻找的人找到此解决方案

var = StringVar(window2)
var.set(OptionList[0])
var.trace_add('write', lambda *args: print(var.get()))
drop = tkinter.OptionMenu(window2, var, *OptionList).grid(row=9, column=1, columnspan=2)
© www.soinside.com 2019 - 2024. All rights reserved.