框架不';t在Tk中加载。(Tk Gui Python)
我是Python编程新手,我做这个项目是为了学习。我的问题是,当我启动应用程序时,框架不';t在Tk中加载。(Tk Gui Python),python,python-2.7,tkinter,tk,Python,Python 2.7,Tkinter,Tk,我是Python编程新手,我做这个项目是为了学习。我的问题是,当我启动应用程序时,main屏幕会显示出来,但之后其他帧不会加载。这些功能是分开工作的动画和文本功能在单独执行时工作。我正试图将它们放在一个应用程序中 import matplotlib.pyplot as plt import matplotlib.animation as animation import time from time import sleep import serial from Tkinter import *
main屏幕会显示出来,但之后其他帧不会加载。这些功能是分开工作的<代码>动画
和文本
功能在单独执行时工作。我正试图将它们放在一个应用程序中
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import time
from time import sleep
import serial
from Tkinter import *
FO = open("SensorValues.txt", "w+")
ser = serial.Serial()
ser.baudrate = 9600
ser.port = '/dev/ttyUSB0'
ser.open()
data = ser.readline(5)
FO.write(data + '\n')
FO.flush()
def organizer(frame):
frame.tkraise()
root = Tk()
MainScreen = Frame(root)
LiveGraph = Frame(root)
LiveLabel = Frame(root)
for frame in (MainScreen,LiveGraph,LiveLabel):
frame.grid(row=0,column=0,sticky='news')
Label(MainScreen,text = 'Choose what do you want').pack()
def animate(i):
fig = plt.figure()
ax1 = fig.add_subplot(2,1,1)
ax2 = fig.add_subplot(2,1,2)
sleep(1)
dataArray = FO.split('\n')
xar = []
yar = []
for eachLine in dataArray:
if len(eachLine)>1:
x,y = eachLine.split(',')
xar.append(int(x))
yar.append(int(y))
ax1.clear()
ax2.clear()
ax1.plot(xar)
ax2.plot(yar)
ani = animation.FuncAnimation(fig, animate, interval=1000)
plt.show()
def texting():
LiveLabel.config(text=data)
root.after(1, texting)
organizer(MainScreen)
Button(MainScreen, text = 'Press for starting live graph!', width = 30, command = lambda:organizer(LiveGraph)).pack()
Button(MainScreen, text = 'Press for starting live label!', width = 30, command = lambda:organizer(LiveLabel)).pack()
Label(LiveGraph,text = '1st Table Temperature - 2nd Table Humidity').pack()
Button(LiveGraph,text = 'Stop',width = 10, command = root.destroy ).pack()
Button(LiveLabel,text = 'Stop',width = 10, command = root.destroy ).pack()
plt.show()
FO.close()
ser.close()
root.mainloop()
截图:
我试图让问题更容易阅读,希望您不介意:)框架正在显示,但您的图形没有添加到其中。请参阅,谢谢您的编辑和参考。这很有帮助:)@JacquesGaudin