python gui设计tkinter为啥不出excel表格_将matplotlib画布嵌入到tkinter GUI plot中没有显示,但是没有抛出错误...

#Script begins here

from tkinter import *

from tkinter import messagebox

import matplotlib

matplotlib.use("TkAgg")

from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg

from matplotlib import animation

from matplotlib import style

from matplotlib.figure import Figure

PROGRAM_NAME = 'Smart Farm Controller'

style.use('ggplot')

fig = Figure(figsize=(5, 30), dpi=100)

a = fig.add_subplot(111)

class Controller:

def __init__(self, root):

self.root = root

self.root.title(PROGRAM_NAME)

self.root.protocol('WM_DELETE_WINDOW', self.exit_app)

self.init_gui()

def create_right_graphs(self):

right_frame = Frame(self.root)

right_frame.grid(row=2, column=6, sticky=N+E+W+S,

padx=2, pady=2)

anim = animation.FuncAnimation(fig, self.animate_graph(right_frame),

interval=1000)

def create_left_switches(self):

left_frame = Frame(self.root)

left_frame.grid(row=2, column=1, columnspan=6, sticky=N+E+W+S,

padx=2, pady=2)

led_button = Button(left_frame, text='LED') #command=self.on_led_button_clicked)

led_button.config(height=2, width=30)

led_button.grid(row=2, column=0, padx=4, pady=8)

apump_button = Button(left_frame, text='Air Pump') #command=self.on_apump_button_clicked)

apump_button.config(height=2, width=30)

apump_button.grid(row=3, column=0, padx=4, pady=8)

wpump_res_button = Button(left_frame, text='Reservoir Water Pump')

#command=self.on_wpump_res_button_clicked)

wpump_res_button.config(height=2, width=30)

wpump_res_button.grid(row=4, column=0, padx=4, pady=8)

wpump_grow_button = Button(left_frame, text='Grow Bucket Water Pump')

#command=self.on_wpump_grow_button_clicked)

wpump_grow_button.config(height=2, width=30)

wpump_grow_button.grid(row=5, column=0, padx=4, pady=8)

def animate_graph(self, right_frame):

pullData = open("sample_graph_data.txt","r").read()

dataList = pullData.split('\n')

xList = []

yList = []

for eachLine in dataList:

if len(eachLine)>1:

x, y = eachLine.split(',')

xList.append(int(x))

yList.append(int(x))

a.clear()

a.plot(xList, yList)

canvas = FigureCanvasTkAgg(fig, right_frame)

canvas.show()

canvas.get_tk_widget().pack(side=RIGHT, fill=BOTH, expand=True)

def init_gui(self):

self.create_right_graphs()

self.create_left_switches()

def exit_app(self):

if messagebox.askokcancel("Quit", "Really quit?"):

self.root.destroy()

if __name__ == '__main__':

root = Tk()

Controller(root)

root.mainloop()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值