【发布时间】:2016-03-28 15:31:45
【问题描述】:
我目前正在为我的滑翔机开发一个小型 Projekt。 Tkinter 应用程序应该使用 RPi 自动启动,然后打开一个名为 XCSOAR 的应用程序或直接退出。 它正在使用按钮,但由于我在飞机上没有鼠标,我需要将它绑定到键。 它已经在 Windows 上运行了,但不在我的树莓派上。 我猜是焦点的问题?
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,因为按钮不发送事件但按键发送。
-
Well Up 无法正常工作
-
Well Up 无法正常工作。 DOWN 应该关闭应用程序。谢谢你的另一个小费已经改变了。我发现如果我在我的应用程序运行时在键盘上写随机的东西然后关闭它,我会在 python IDLE 中写入。这可能是问题吗?已经尝试用 .focus() 解决这个问题,但没有成功