-1
>>> 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'

The same error is also generated for its current() method.

CDJB
  • 14,043
  • 5
  • 29
  • 55
cybermizz
  • 1
  • 4
  • The code you posted will not give that error. Is your real code something like `cboCombo = ttk.Combobox(...).pack(...)` or `cboCombo = ttk.Combobox(...).grid(...)`? – Bryan Oakley Jan 28 '20 at 22:30
  • Thank You, Daniel Huckson, your answer really help me. I'm new to Tkinter, and my question was valid but the person who disagrees with my question by sharing the pre-existing solution. But I tell you, I already used it, and it was not helpful. But Daniel, thank you ones more. – cybermizz Jan 29 '20 at 04:57
  • Your problem may indeed be valid, but the question was not. The code you posted literally does not give the error you say it does. At least, it doesn't when we have to fill in the missing code with what we think necessary. If you can provide a complete [mcve] that replicates the problem, we can certainly consider re-opening your question. – Bryan Oakley Jan 29 '20 at 05:14
  • My code represents an issue as spotted by Daniel that I was doing wrong to get the value from the object of Combobox but not from it's attribute like textvariable. – cybermizz Jan 29 '20 at 10:10
  • But you _aren't_ doing it wrong - using the combobox's `get()` method is a perfectly valid way of getting the value. In fact, I would argue it's the correct way, as it doesn't require an extra object that has to be managed. The problem isn't that you're getting it from the object, the problem is that you're getting it from a variable that is set to `None`. The root cause of the problem lies elsewhere. – Bryan Oakley Jan 29 '20 at 13:56
  • Okay, Sir, you might be right but I got that issue and it gets resolved by applying Daniel's solution. Thank you – cybermizz Jan 29 '20 at 13:59
  • It doesn't solve the issue, it works around it. That might be good enough, but you still have the issue that `cboCombo` is set to `None`. Any other time you need to access the combobox (to call `configure`, `destroy`, etc) you'll get the same error. As long as you don't need to call any methods on the combobox once you've created it, that won't be a problem. – Bryan Oakley Jan 29 '20 at 14:04
  • Okay, Thank You! – cybermizz Jan 29 '20 at 14:11

1 Answers1

0

User 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()
Daniel Huckson
  • 1,157
  • 1
  • 13
  • 35