This question already has answers here:
Tkinter: AttributeError: NoneType object has no attribute <attribute name>
                                
                                    (2个答案)
                                
                        
                                上个月关闭。
            
                    
>>> keyvalue = ('cat', 'dog')
>>> cboCombo = ttk.Combobox(root, values=keyvalue, width=68)
>>> value = cboCombo.get()

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'get'


其current()方法也会生成相同的错误。

最佳答案

用户tkinter StringVar。

import tkinter as tk

var = tk.StringVar()
keyvalue = ('cat', 'dog')
cboCombo = ttk.Combobox(root, values=keyvalue, textvariable=var, width=68)
value = var.get()

关于python - 当我从组合框选择值时,get方法会导致错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/59957267/

10-13 04:21