Domanda

Just the question from the title "Why is there NoneType when should be Label?" And how to solve it to be able to modify the label text in the onComboBoxChange?

label1 = Tkinter.Label( frame, text = '1.0' ).grid( row = 4, column = 5 )

nums = ( 'one', 'two' )
v1 = Tkinter.StringVar()
v1.trace( 'w',
    lambda name, index, mode, sv = v1: self.onComboboxChange( sv, label1 ) )
ttk.Combobox( frame, textvar = v1, values = nums,
    state = 'readonly', width = 14 ).grid( row = 2, column = 1 )

def onComboboxChange( self, sv, label ):
    label.config( text = 'smth' ) # ------------- why do I get NoneType here?
È stato utile?

Soluzione

label1 = Tkinter.Label( frame, text = '1.0' ).grid( row = 4, column = 5 )

.grid doesn't return anything. You want to save the actual widget before calling grid.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top