Salut, je comprends pas pourquoi mon combobox se transforme en INT, pourriez vous m'aider svp ? Concrètement que dois je faire pour passer le widget en argument de com() pour récupérer sa valeur svp ?
Mon code me renvoie :
.!example.!toplevel.!combobox
1280

Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\Anon\Anaconda3\lib\tkinter\__init__.py", line 1699, in __call__
return self.func(*args)
File "C:/Users/Anon/.spyder-py3/AssetsManagement/Mission3.py", line 18, in <lambda>
w.config(postcommand=lambda: com(w, winMi3))
File "C:/Users/Anon/.spyder-py3/AssetsManagement/Mission3.py", line 8, in com
lb = ttk.Label(win, width=300, text=w.get(), anchor="center")
AttributeError: 'int' object has no attribute 'get'

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# -*- coding: utf-8 -*-
from tkinter import Frame, Tk, Toplevel
import tkinter.ttk as ttk
import os
 
def com(w, win):
    print(w)
    lb = ttk.Label(win, width=300, text=w.get(), anchor="center")
    lb.pack()
 
def openMi3(root):
    winMi3 = Toplevel(root)
 
    w = ttk.Combobox(winMi3, values=['testOption1','test2'])
    print(w)
    w.current(newindex=0)
    w.pack()
    w.config(postcommand=lambda: com(w, winMi3))
 
    bouton = ttk.Button(winMi3, text="关闭", command=winMi3.destroy)
    bouton.pack()
 
    winMi3.geometry("300x300+100+100")
 
def main():
    root = Tk()
    ex = Example(root)
    root.geometry("300x300+100+100")
    root.mainloop()
 
class Example(Frame):
    def __init__(self, parent):
        Frame.__init__(self, parent)
        self.parent = parent
        self.initUI()
 
    def initUI(self):
        openMi3(self)
 
if __name__ == '__main__':
    main()