[update] pybfm.py を TkinterDnD2 がなくても起動するよう変更

This commit is contained in:
ocogeclub 2022-08-11 20:33:56 +09:00
parent 36c3497492
commit e92fbfc6ed
3 changed files with 226 additions and 215 deletions

4
.gitignore vendored
View File

@ -6,5 +6,7 @@ build/
*.bak *.bak
*.old *.old
out/ out/
.mypy_cache
tkinterdnd2

View File

@ -1,7 +1,12 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
from tkinter import * from tkinter import *
from tkinterdnd2 import * try:
from tkinterdnd2 import *
except ImportError:
dnd = False
else:
dnd = True
import os import os
import sys import sys
import pyboard import pyboard
@ -174,7 +179,10 @@ def do_nothing():
##### メイン ##### ##### メイン #####
# メインウィンドウの生成 # メインウィンドウの生成
root = TkinterDnD.Tk() if dnd:
root = TkinterDnD.Tk()
else:
root = Tk()
root.title('PyBfm') root.title('PyBfm')
root.geometry('400x300') root.geometry('400x300')
pmenu = Menu(root, tearoff=0) pmenu = Menu(root, tearoff=0)
@ -191,8 +199,9 @@ pmenu.add_command(label="閉じる", command=do_nothing)
frame = Frame(root) frame = Frame(root)
# Listboxウィジェットの生成 # Listboxウィジェットの生成
listbox = Listbox(frame, selectmode=EXTENDED) listbox = Listbox(frame, selectmode=EXTENDED)
listbox.drop_target_register(DND_FILES) if dnd:
listbox.dnd_bind('<<Drop>>', listbox_drop) listbox.drop_target_register(DND_FILES)
listbox.dnd_bind('<<Drop>>', listbox_drop)
listbox.bind("<KeyPress>", input_key) listbox.bind("<KeyPress>", input_key)
listbox.bind("<Double-Button-1>", dbl_click) listbox.bind("<Double-Button-1>", dbl_click)
listbox.bind("<Button-3>", pop_menu) listbox.bind("<Button-3>", pop_menu)