Computer >> 컴퓨터 >  >> 프로그램 작성 >> Python

Tkinter 목록 상자에서 선택 항목을 강조 표시하는 방법은 무엇입니까?

<시간/>

디렉토리에서 여러 파일을 계속 선택하고 클립보드에 복사한 후 모든 파일을 다른 디렉토리에 붙여넣어야 하는 특정 시스템의 상황을 고려해 보겠습니다. ListBox에서 여러 항목을 선택하는 아이디어는 exportselection을 사용하여 수행할 수 있습니다. 특성. 다른 ListBox에서 항목을 선택하는 동안 Listbox가 선택 항목을 유지하도록 합니다. 선택 항목을 일정하게 유지하는 것처럼 작동하도록 목록 상자를 구성하려면 exportselection =False를 만들 수 있습니다. .

예시

#Import tkinter library
from tkinter import *
#Create an instance of Tkinter frame or window
win= Tk()
#Set the geometry of tkinter frame
win.geometry("750x350")
listboxA=Listbox(win, exportselection=False) #Create listboxA
listboxA.pack(padx=10,pady=10,fill=BOTH,expand=True)
listboxB=Listbox(win,exportselection=False) #Create ListboxB
listboxB.pack(padx=10,pady=10,fill=BOTH,expand=True)
listboxA.insert(1, "Python")
listboxA.insert(2, "Java")
listboxA.insert(3, "C++")
listboxA.insert(4, "Rust")
listboxA.insert(5, "GoLang")
listboxB.insert(1, "C#")
listboxB.insert(2, "JavaScript")
listboxB.insert(3, "R")
listboxB.insert(4, "Php")
win.mainloop()

출력

위의 코드를 실행하면 두 개의 목록 상자가 포함된 창이 표시됩니다. 선택하는 동안 두 목록 상자에서 여러 항목을 선택할 수 있습니다.

Tkinter 목록 상자에서 선택 항목을 강조 표시하는 방법은 무엇입니까?