Home > Software engineering >  Tkinter Combox selected letter once
Tkinter Combox selected letter once

Time:10-12

These codes work good by keeping track of the existing values from on each click . I want to add sentence "Selected letter" and using "," between each letter. like that: "Selected letter g,Q,p". I also want to make limitation each character can be selected once from combobox. Thanks .

    import tkinter as tk
from tkinter.ttk import Combobox

form=tk.Tk()
form.title("Pi Theorem")
form.geometry("300x300")


def Add():
    textbox.insert(END, combobox.get())

#buton
buton=tk.Button(form,text='EKLE',fg='black',command=Add)

buton.place(x=200,y=50,height=20)

#entry - textbox
textbox=tk.Entry(fg='black',bg='white')
textbox.pack(ipady=10)
textbox.place(width=150,height=20,x=20,y=100)

#combobox 
degiskenler=['g','Q','p','H','M']
combobox=Combobox(form, values=degiskenler,height=3)
combobox.pack()
combobox.place(width=150,height=20,x=20,y=50)

form.mainloop()

CodePudding user response:

Simply use a set to store the selected letters, then use string.join() to join the selected letters and insert the result to textbox:

letters = set()

def Add():
    letters.add(combobox.get())
    textbox.delete(0, tk.END)
    textbox.insert(tk.END, 'Selected letter ' ','.join(letters))
  • Related