내가 파일을 강조 제거를위한 키보드 버튼을 강조하기위한 하나의 왼쪽 버튼을 클릭 한 다음 폴더에서 파일 이름을 파일을 가져올하고 "삭제"를, 우분투에서 파이썬 프로그램을 쓰고 있어요사용하는 경우 문
한 번의 클릭으로 잘 작동하고 있습니다. 하지만 삭제 버튼을 누르면 작동하지 않으며 파일 이름을 완전히 삭제하는 작업이 시작됩니다.
키보드에서 "삭제"버튼을 눌렀을 때 다중 기능을 추가하려고합니다.
IF ... THEN 문과 함께 "삭제"버튼을 어떻게 사용합니까?
import subprocess,os
from Tkinter import *
def text_click_callback(event):
# an event to highlight a line when single click is done
line_no = event.widget.index("@%s,%s linestart" % (event.x, event.y))
line_end = event.widget.index("%s lineend" % line_no)
event.widget.tag_remove("highlight", 1.0, "end")
event.widget.tag_add("highlight", line_no, line_end)
event.widget.tag_configure("highlight", background="yellow")
the_text = event.widget.get(line_no, line_end)
tex.tag_bind(the_text, "<Delete>", lambda event, the_text1 = path+'/'+the_text: os.remove(the_text1))
def viewFile():
tex.delete('1.0', END)
for f in os.listdir(path):
linkname="link-" + f
tex.insert(END,f + "\n", linkname)
tex.tag_configure(linkname, foreground="blue", underline=True)
tex.tag_bind(linkname, "<Button-1>", text_click_callback) # highlight a line
if __name__ == '__main__':
root = Tk()
step = LabelFrame(root,text="FILE MANAGER", font = "Arial 20 bold italic")
step.grid(row=1, columnspan=7, sticky='W',padx=100, pady=5, ipadx=130, ipady=25)
Button(step, text="ViewFile", font = "Arial 8 bold italic", activebackground="turquoise", width=30, height=5, command=viewFile).grid (row= 6, column =3)
Button(step, text="Exit", font = "Arial 8 bold italic", activebackground="turquoise", width=20, height=5, command=root.quit).grid (row= 6, column =5)
tex = Text(master=root) # TextBox For Displaying File Information
scr=Scrollbar(root,orient =VERTICAL,command=tex.yview)
scr.grid(row=8, column=2, rowspan=15, columnspan=1, sticky=NS)
tex.grid(row=8, column=1, sticky=E)
tex.config(yscrollcommand=scr.set,font=('Arial', 8, 'bold', 'italic'))
global process
path = os.path.expanduser("/tmp") # Define path To play, delete, or rename video
root.mainloop()
는 아마도 이것은 (http://effbot.org/tkinterbook/tkinter-events-and-bindings.htm) 당신을 도울 것입니다. – BurningKarl
tag_bind는 delete를 누를 때 전파를 멈추기 위해 "break"를 반환하지 않으므로 까다로울 것입니다. 기타 [여기] (http://stackoverflow.com/questions/13066773/python-tkinter-stopping-event-propagation-in-text-widgets-tags). 텍스트 위젯 대신 목록 상자를 사용하여 심각하게 재검토해야한다고 생각합니다. 텍스트 위젯은 당신이하고 싶은 것을 위해 설계되지 않았습니다. 목록 상자가있었습니다. – Marcin
전체 프로그램을 TextBox에서 ListBox로 바꿀만큼 좋지 않습니다. 제발 ... 저를 도울 수 있다면 ... Thanak You – Fahadkalis