python图形用户界面形式_Python图形用户界面和动画

我正在创建一个图形用户界面,用tkinter绘制温度传感器的实时图形,并从matplotlib中创建动画函数。我得到了漂亮的现场图表。但我面临的问题是,运行应用程序后,实时图形就开始运行了。我已经创建了一个按钮来调用类StartPage中的命令,但它不起作用。我希望我的应用程序在我单击class StartPage中的开始监视时开始收集数据和绘制图形

如果有人能帮我这个忙,那就太好了。在

谢谢你。在def animate(i):

ipcon = IPConnection() # Create IP connection

ptc1 = BrickletPTC(UID1, ipcon) # S3

ptc2 = BrickletPTC(UID2, ipcon) # S7

ptc3 = BrickletPTC(UID3, ipcon) # S7

ptc4 = BrickletPTC(UID4, ipcon) # S7

ipcon.connect(HOST, PORT) # Connect to brickd

temperature1 = ptc1.get_temperature() - 20

temperature2 = ptc2.get_temperature() + 6

temperature3 = ptc3.get_temperature() + 3

temperature4 = ptc4.get_temperature() + 29

l = [temperature1, temperature2]

avgTemp = np.mean(l)

avgTempM = str(avgTemp/100)

dataArrayavg = avgTempM.split(',')

tempavg = float(dataArrayavg[0])

tempCavg.append(tempavg)

avg.set_xlabel('Time [s]', fontsize = 10)

avg.set_ylabel('Temperature [°C]', fontsize = 10)

y_formatter = matplotlib.ticker.ScalarFormatter(useOffset=False)

avg.yaxis.set_major_formatter(y_formatter)

titleavg = "Average Room Temperature: " + str(temperature1/100) + " °C"

avg.set_title(titleavg, fontsize = 12)

avg.plot(tempCavg, "#483D8B")

f1.savefig('RoomTemperature.png')

f2.savefig('ObjectTemperature.png')

class StartPage(tk.Frame):

def __init__(self, parent, controller):

tk.Frame.__init__(self, parent)

# Adding a logo to the startpage

logo = Image.open("Gemeinschaftslogo(5).jpg")

Image1 = ImageTk.PhotoImage(logo)

# defining the image label

imageLabel = Label(self, image = Image1)

imageLabel.image = Image1

imageLabel.pack(pady=30, padx=30)

#defining labels

label = ttk.Label(self, text="Zustandsüberwachung (Condition Monitoring) von industriellen Computertomographie-Systemen", font = LARGE_FONT,)

label.pack(pady=10, padx=10)

#creating button

#if agree then move to temperature graph

button1 = ttk.Button(self, text="Start Monitoring",

command=lambda: animate()) # with lambda we are moving from start page to page 1

button1.pack(pady=30, padx=30)

button2 = ttk.Button(self, text="Enter",

command=lambda: controller.show_frame(RoomTempGraph)) # with lambda we are moving from start page to page 1

ani1 = animation.FuncAnimation(f1,animate, interval = 1000)

app.mainloop()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值