Home > Net >  Listbox output Python
Listbox output Python

Time:11-08

Good evening. Let's get started: I first started using Listbox in Tkinter, and I need to get some action from each value. For example: The user clicks 'use encrypted' and he gets one action related to encryption, and if he clicks 'use decrypted', he gets a second action that is not related to encryption. How can this be realized? Code below:

from tkinter import *

window = Tk()

window.title('Login')
window.geometry('300x200')

# This Error:
def crypt():                               
    r = (lis.get(lis.curselection))
    c = (lis.get(lis.curselection))

    if r == r:
        print('Hello')
    
    if c == c:
       print('World')


r = ['Use encrypted']
c = ['Use decrypted']
lis = Listbox(window, selectmode=SINGLE, width=30, height=2)
lis.grid()
for i in r:
    lis.insert(END, i)  
for i in c:
    lis.insert(END, i)


button = Button(window, text='Enter', command=crypt)
button.grid(pady=30)



window.mainloop()

CodePudding user response:

The code raises an error on clicking the button. Because you missed the parenthisis to call the curselection function

(lis.get( lis.curselection() ))
  • Related