現在、私のグライダー用の小型プロジェクトに取り組んでいます。 TkinterアプリはRPiで自動起動し、XCSOARというアプリを開くか、単に終了する必要があります。 ボタンを使って作業していますが、飛行機に乗っている私にはマウスがないので、キーにバインドする必要があります。 これは既にWindows上で動作していますが、私のラズベリーパイでは動作していません。 私はその焦点に問題があると思いますか?Tkinterキーバインディングが機能しません
from Tkinter import *
import os
class MainWindow:
def __init__(self, master):
frame = Frame(master)
master.configure(background="white")
master.overrideredirect(True)
master.geometry("{0}x{1}+0+0" .format(root.winfo_screenwidth(), root.winfo_screenheight()))
master.bind("<Up>", self.xcsoar1)
master.bind("<Down>", self.startx1)
frame.pack()
photo1=PhotoImage(file="XCS.gif")
self.button1 = Button(frame, image=photo1, command = self.xcsoar, background="white")
self.button1.image = photo1
self.button1.pack()
photo3=PhotoImage(file="center.gif")
self.center = Label(frame, image = photo3, background="white")
self.center.image = photo3
self.center.pack()
photo2=PhotoImage(file="RPi.gif")
self.button2 = Button(frame, image=photo2, command = self.startx, background="white")
self.button2.image=photo2
self.button2.pack()
def xcsoar(self):
os.system('xcsoar.exe')
root.destroy()
def startx(self):
root.destroy()
def xcsoar1(self, event):
os.system('xcsoar.exe')
root.destroy()
def startx1(self, event):
root.destroy()
root = Tk()
b = MainWindow(root)
root.mainloop()
問題はローカルコンピュータでは動作しますが、そのプラットフォームでは動作しないので、私はrasberry pieにタグを付けます。おそらくこの問題を克服した専門家かもしれません –
あなたの書式設定によって人がオフになることもあります。あなたはそのコードダンプをクリーンアップできますか?たとえば、誰がボタン画像の写真であるか気にして、その行を削除します。ボタンが機能する場合は、それらも削除します。ウィンドウの幾何学は重要ですか?単一行のコールバックでこれを作り直すことができますので、読みやすくなりますか? 「最小限の作業例」はここでは非常に便利です。 –
実際に何かを行う唯一の鍵は、Upです。それは動作しますか?また、ボタンはイベントを送信しないが、キーを押すとデフォルトの "event = None"というイベントを与えると、ボタンはxcsoar1を呼び出すことができます。 –