我正在开发Windows机器上的以下tkinter代码(并且正在工作),但是当移动到raspberry pi(Pyhton 3.2)时,没有用。它没有任何错误(在shell上)并且控制台打印正在运行。实际的GUI缺失.....
我尝试了其他较小的修补程序,并且工作正常。 在raspberry pi上,我进入菜单,编程,空闲3,打开文件并执行它。
我可以查看任何日志文件吗?
代码基本上有2页,在第一页上我显示了两个varibles aux [0]和aux [1]。这些值通过串行COM在更新功能下捕获。 仪表类是实际的仪表图。 在更新功能中,您可以看到打印功能,它在shell中显示这些值。这很有效。
知道可能出现什么问题吗?
import serial
from tkinter import *
import tkinter as tk
import tkinter.font as tkf
import math
LARGE_FONT= ("Verdana", 12)
data = [20, 15, 10, 7, 5, 4, 3, 2, 1, 1, 0, 23,12,4,2,0,9,4]
c_height = 350
velocidad_total=0
direccion_total=0
i=0
direccion=[]
velocidad=[]
ser = serial.Serial('COM2')# ttyUSB0
ser.baudrate = 9600
class Meter(tk.Canvas):
def __init__(self,master,tod,*args,**kwargs):
super(Meter,self).__init__(master,*args,**kwargs)
#tod='day'
self.layoutparams(tod)
self.graphics(tod)
self.createhand(tod)
self.setrange()
def layoutparams(self,tod):
# set parameters that control the layout
height = int(self['height'])
def set(self,direccion,velocidad):
# call this to set the hand
# convert value to range 0,100
#deg = 300*(direccion - self.start)/self.range - 240
self.itemconfigure(self.textid,text = str(velocidad))
rad = math.radians(direccion-90)
# reposition hand
self.coords(self.handid,self.centrex+30*math.cos(rad)
,self.centrey+30*math.sin(rad)
,self.centrex+self.handlen*math.cos(rad), self.centrey+self.handlen*math.sin(rad))
#self.coords(self.handid,self.centrex+25*math.cos(rad-0.31),self.centrey-15*math.sin(rad-0.31)
# ,self.centrex+15*math.cos(rad+0.31),self.centrey-25*math.sin(rad+0.31),self.centrex+90*math.cos(rad),self.centrey-90*math.sin(rad))
def blob(self,colour):
# call this to change the colour of the blob
self.itemconfigure(self.blobid,fill = colour,outline = colour)
the meter class continues. Omited to make this as short as possible
class SeaofBTCapp(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
container = tk.Frame(self)
container.pack(side="top", fill="both", expand = True)
container.grid_rowconfigure(0, weight=1)
container.grid_columnconfigure(0, weight=1)
self.frames = {}
for F in (StartPage, PageOne, PageTwo):
frame = F(container, self)
self.frames[F] = frame
frame.grid(row=0, column=0, sticky="nsew")
self.show_frame(StartPage)
def show_frame(self, cont):
frame = self.frames[cont]
frame.tkraise()
class StartPage(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self,parent)
label = tk.Label(self, text="Start Page", font=LARGE_FONT)
#label.pack(pady=10,padx=10)
label.grid(column=0,row=0)
button = tk.Button(self, text="HISTORIA",
command=lambda: controller.show_frame(PageOne))
#button.pack()
button.grid(column=0, row=1,sticky=(E) )
button2 = tk.Button(self, text="NOCHE",
command=lambda: controller.show_frame(PageTwo))
#button2.pack()
button2.grid(column=1, row=1, sticky=(W))
self.print_value()
def print_value(self):
w=Meter(self,height = 400,width = 400,tod='day')
#w.pack()
w.grid (column=0, row =3,columnspan=3,rowspan=3)
if len(direccion)!=0:
w.set(int(direccion[-1]),int(velocidad[-1]))
class PageOne(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
label = tk.Label(self, text="Page One!!!", font=LARGE_FONT)
label.pack(pady=10,padx=10)
button1 = tk.Button(self, text="Back to Home",
command=lambda: controller.show_frame(StartPage))
button1.pack()
button2 = tk.Button(self, text="Page Two",
command=lambda: controller.show_frame(PageTwo))
button2.pack()
self.imprimir()
self.canvas = Canvas(self, width=400, height=400, bg = 'white')
self.canvas.pack()
def update():
global velocidad_total
global direccion_total
global i
c = StringVar()
c=ser.readline()
aux2= str(c, 'utf-8')
aux = aux2.split(" ")
direccion.append(int(aux[0]))
velocidad.append(int(aux[1]))
velocidad_total = velocidad_total+velocidad[i]
direccion_total = direccion_total+direccion[i]
if (i>299): # para retener 5 min de estadisticas que llegan c/u 1seg
i=0
velocidad_media= velocidad_total/300
direccion_media = direccion_total/300
print (aux[0]," ",aux[1])
#theta.set(c)
#w.set(aux[0],aux[1])
app.after(100,update)
app=SeaofBTCapp()
app.after(100,update)
app.mainloop()
答案 0 :(得分:0)
解决此问题的最佳方法是创建mcve。这将要求您在仍然看到问题的同时删除尽可能多的代码。最终你将删除一些东西,错误将消失。然后,您将知道导致问题的代码。 “
我的猜测是,它只是在等待这行代码的数据:
c=ser.readline()