[Python] Passif button-1 event to postgresql function

Discussão em 'Python' iniciado por Stack, Maio 17, 2025.

  1. Stack

    Stack Membro Participativo

    I want to pass a button clicked event to a postgresql function. Then, I want to use the event passed

    to identify the combobox I left-clicked on so that I could insert an item selected from a listbox to that combobox. Here is the my codes:

    from tkinter import *
    from tkinter import ttk

    def show_combo_screen():
    ecran_combo_cptes=Tk()
    ecran_combo_cptes.geometry('300x200')

    my_label=Label(ecran_combo_cptes, text='Click on a dropdown to show
    choices')

    my_label.pack(pady=20)

    combo1=ttk.Combobox(ecran_combo_cptes, state='disabled')
    combo1.pack(pady=20)

    combo2=ttk.Combobox(ecran_combo_cptes, state='disabled')
    combo2.pack(pady=20)

    def show_listbox_of_choices(event):
    window = Toplevel()

    my_list_var=StringVar()
    my_list=Listbox(window,listvariable=my_list_var, width=35,
    selectmode='browse')

    my_list.pack(pady=20)

    option_lists=['CHOICE1','CHOICE2','CHOICE3','CHOICE4']

    for item in option_lists:
    my_list.insert(END, item)

    def validate_selected_cpte(event):
    combo_clicked=event.widget

    # Add choice to combobox
    combo_clicked.configure(values=[my_list.get(ANCHOR)])
    combo_clicked.current(0)

    btn=Button(window, text='Validate choice',
    command=lambda:validate_selected_cpte(event))

    btn.pack(side='right')

    combo1.bind('<Button-1>',show_listbox_of_choices)
    combo2.bind('<Button-1>',show_listbox_of_choices)

    show_combo_screen()


    I read Postgresql document and tried to find an answer related to my issue on this website, I could not find anything. My issue is that, I do not know what datatype to pass to the function for that kind of

    event.

    Thanks in advance for answers!

    Continue reading...

Compartilhe esta Página