Yazı Font Küçült Yazı Font Büyült

ListBox ta Seçili Satırları Silmek

 

Merhaba arkadaşlar bu makalemizde listbox ta seçili satırları sileceğiz.  Listbox yapısı aşağıdaki gibidir.

 

lbox= Listbox(root, selectmode= MULTIPLE,bd=1, width=70,height=12, font=('Times', 14))

 

listbox ta itemsleri seçebilmemiz için selectmode özelliğini multiple yapmalıyız.

 

 

 

Resim1

Şekil 1

 

 

Resim2

Şekil 2

 

 

Resim3

Şekil 3

 

 

#Import the required libraries.. gereken kutuphane dosyalarini import ediyoruz.

from tkinter import *

from tkinter import messagebox

import tkinter as tk

 

#Create an instance of tkinter frame or window

#tkinter cercevesi veya pencere ornegi olusturuyoruz

root= Tk()

root.title("msssql db example...bs")

#Set the geometry. formumuzun genislik ve yuksekligini tayin ediyoruz

root.geometry("800x500")

 

#Create a text Label.. label nesnesi ekliyoruz

label= Label(root, text="Select items from the list..." +"\n" + "Listeden item seciniz...", font= ('Poppins bold', 18))

label.pack(pady= 20)

 

#Define the function..fonksiyon tanimliyoruz

def delete_item():

 

   MsgBox = tk.messagebox.askquestion ('Delete Items','Are you sure you want to delete item(s)'+'\n'+"Secili itemsleri silmek istediginizden emin misiniz?",icon = 'warning')

   if MsgBox == 'yes':

 

    selected_item = lbox.curselection()

   for item in selected_item[::-1]:

    lbox.delete(item)

   else:

    tk.messagebox.showinfo('Return','You will now return to the application screen'+'\n'+"Uygulama ekranina geri doneceksiniz",icon = 'info')

 

lbox= Listbox(root, selectmode= MULTIPLE,bd=1, width=70,height=12, font=('Times', 14))

lbox.pack()

 

#add items.. listboxa items ekliyoruz

items=[

 '1   Bahadir  Sahin    basahin@hotmail.com',

 '2   Melissa  Parker   melparker@gmail.com',

 '3   Tommy    Paton    tommypat@hotmail.com',

 '4   Alice    May      alicemay12@hotmail.com',

 '5   Michael  Alon     michaelal57@gmail.com',

 '6   Mike     Carson   mikecarson33@hotmail.com'

 '7   Tracy    Abbot    tracyabbot82@hotmail.com',

 '8   Nancy    White    nancywh@gmail.com',

 '9   Jack     Fox      jackfox89@hotmail.com',

 '10 Alina    Benson   alinabens2@hotmail.com',

 '11 Joe      Eagle    joeeagle7@gmail.com',

 '12 Johanna  Manson   johannamans@hotmail.com',

 '13 Emilia   Peterson emiliapets@hotmail.com'

  ]

 

#Now iterate over the list.. simdi listeyi tekrarla

for item in items:

   lbox.insert(END,item)

 

#Create a button to remove the selected items in the list.. 

#listedeki secili itemleri kaldirmak icin buton nesnesi ekliyoruz  

 

Button(root, text= "Delete (Sil)",width=30,height=2,font='arial 14 bold', command= delete_item).pack(pady= 20)

 

#Keep running the window.. pencereyi calistirmaya devam et.

root.mainloop()

 

 

 

Bir makalenin daha sonuna geldik. Bir sonraki makalede görüşmek üzere. Bahadır ŞAHİN