Home > Enterprise >  Comparing any values. from a list to what puts in the entry box in tkinter
Comparing any values. from a list to what puts in the entry box in tkinter

Time:07-18

i want to to take information using entry widget and to compare and see if the input in the entry box equals to one or more strings that i store inside a list i tried :

if Entry.get() == any MyList[]:
          Mylable.pack()

also:

if Entry.get() == MyList[0:10]:
          MyLable.pack()

CodePudding user response:

You can use the in operator, which can check if a value is present anywhere inside of a list:

if Entry.get() in MyList:
    Mylable.pack()

Or if you want to check to see if the entry text is in the first 10 elements of MyList:

if Entry.get() in MyList[0:10]:
    MyLable.pack()
  • Related