Python Forum
[Tkinter] tkinter listbox problem
Thread Rating:
  • 1 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] tkinter listbox problem
#1
Hi
i have a problem with the Listbox on Tkinter.
When i select with mouse one word in the Listbox, the program give me the relative code.
If i select another word again in the Listbox the program put the new code under the first one.
I would like that at the second selection the code before disappear.

What can I have to change?

THANK U!

(sorry for my english Smile )

This is my code:

from tkinter import *
from tkinter.font import Font

root = Tk()
text = Text(root)

myFont = Font(family="Times New Roman", size=12)
text.configure(font=myFont)



class articoli: 

    def __init__(self,codice,modello,pezzi_ora,cod_materiale,mis_materiale,
                 ultima_mod,materiale_casa):

        self.codice = codice
        self.modello = modello
        self.pezzi_ora = pezzi_ora
        self.cod_materiale = cod_materiale
        self.mis_materiale = mis_materiale
        self.ultima_mod = ultima_mod
        self.materiale_casa = materiale_casa

        

        self.label_8 = Label() 
        self.label_8.configure(text=self.codice,font=myFont)
        self.label_8.pack(side=TOP)

        self.label_9 = Label() 
        self.label_9.configure(text=self.modello,font=myFont)
        self.label_9.pack(side=TOP)

        self.label_10 = Label() 
        self.label_10.configure(text=self.pezzi_ora,font=myFont)
        self.label_10.pack(side=TOP)

        self.label_11 = Label() 
        self.label_11.configure(text=self.cod_materiale,font=myFont)
        self.label_11.pack(side=TOP)

        self.label_12 = Label() 
        self.label_12.configure(text=self.mis_materiale,font=myFont)
        self.label_12.pack(side=TOP)

        self.label_13 = Label() 
        self.label_13.configure(text=self.ultima_mod,font=myFont)
        self.label_13.pack(side=TOP)

        self.label_14 = Label() 
        self.label_14.configure(text=self.materiale_casa,font=myFont)
        self.label_14.pack(side=TOP)


def callback(event):
    value=str((Lb1.get(ACTIVE)))
    print (value)
    sys.stdout.flush()
    
    if value== "Python":
        Ps_48 = articoli("Ps 48","Patt_inf_est","1500","NG00002","135_5","20_04_2018",
                 "20")
    elif value== "Perl":
        Ps_40 = articoli("Ps_40","patt_sup_est","1000","NG00001",
                                 "130_4","18_05_2018","2000") 
    elif value== "C":
        Ps_42 = articoli("Ps_40","patt_sup_est","1000","NG00001",
                                 "135_4","18_05_2018","3000")
    elif value== "PHP":
        Ps_45 = articoli("Ps_40","patt_sup_est","1000","NG00001",
                                 "139_4","18_05_2018","4000")
    elif value== "JSP":  
        Ps_47 = articoli("Ps_40","patt_sup_est","1000","NG00001",
                                 "140_4","18_05_2018","5000")    
      

#listbox definition
Lb1 = Listbox(selectmode=SINGLE)
Lb1.insert(1, "Python")
Lb1.insert(2, "Perl")
Lb1.insert(3, "C")
Lb1.insert(4, "PHP")
Lb1.insert(5, "JSP")

Lb1.pack(side=LEFT,fill=BOTH,expand=YES)
#scrollbar configuration       
scrollbar = Scrollbar()
scrollbar.pack(side=LEFT, fill=Y)
#listbox configuration   
Lb1.config(yscrollcommand=scrollbar.set)
scrollbar.config(command=Lb1.yview)
#double click for listbox
Lb1.bind('<Double-Button-1>',callback)

root.mainloop()
Reply


Messages In This Thread
tkinter listbox problem - by edoardo5782 - Sep-02-2018, 08:28 PM
RE: tkinter listbox problem - by Larz60+ - Sep-02-2018, 10:07 PM
RE: tkinter listbox problem - by edoardo5782 - Sep-04-2018, 04:43 PM
RE: tkinter listbox problem - by Larz60+ - Sep-04-2018, 07:43 PM
RE: tkinter listbox problem - by wuf - Sep-06-2018, 07:24 PM
RE: tkinter listbox problem - by edoardo5782 - Sep-10-2018, 07:10 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Python3 tkinter radiobutton problem Nick_tkinter 14 6,084 Feb-15-2021, 11:01 PM
Last Post: Nick_tkinter
  tkinter python button position problem Nick_tkinter 3 3,581 Jan-31-2021, 05:15 AM
Last Post: deanhystad
  [Tkinter] ClockIn/Out tkinter problem Maryan 2 2,228 Oct-12-2020, 03:42 AM
Last Post: joe_momma
  tkinter| listbox.insert problem Maryan 3 3,538 Sep-29-2020, 05:34 PM
Last Post: Yoriz
  What units does the width parameter of a tkinter Listbox use? Pedroski55 2 5,623 Jul-04-2020, 08:17 AM
Last Post: deanhystad
  Tkinter problem DPaul 6 4,172 May-28-2020, 03:40 PM
Last Post: DPaul
  [Tkinter] Tkinter - I have problem after import varaible or function from aGUI to script johnjh 2 2,609 Apr-17-2020, 08:12 PM
Last Post: johnjh
  [Tkinter] Problem with tkinter when creating .exe file Jan_97 2 4,622 Feb-27-2020, 05:17 PM
Last Post: Jan_97
  [Tkinter] Tkinter problem catlessness 1 2,068 Jan-15-2020, 05:17 AM
Last Post: Larz60+
  Problem with Submit button Tkinter Reldaing 2 3,677 Jan-05-2020, 01:58 AM
Last Post: balenaucigasa

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020