Tkinter串行数据在多个页面上

时间:2018-06-25 02:29:03

标签: python-3.x tkinter

我正在将Python3与TKinter一起使用,即使在阅读了论坛和TKdocs网站后仍然遇到了问题,但我仍然没有取得进展。我通过自己的港口接收温度读数。到目前为止,我的程序有一个“开始”页面和一个带有图形的页面,该图形随每次阅读而更新。所以问题是我怎么也可以在第一页上打印传感器数据,我是tkinter的新手。

如果有任何建议,我都会在下面发布代码。

export default function bind2(data: any) {
  const initialArgs = Array.prototype.slice.call(arguments, 1)

  return (finalArgs: any[]) => this.apply(data, [...initialArgs, ...finalArgs])
};

function decorate(obj: any): any {
  obj.bind2 = bind2
  return obj
}

1 个答案:

答案 0 :(得分:0)

起初我误解了这个问题,所以现在我重写了答案。如果您仍然有疑问或不是您所期望的,请在下面评论。我会尽力帮助。另外,我没有arduino可以检查。

我对您的代码进行了以下更改:

class StartPage(tk.Frame):

    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)

        #Page Labels
        label = tk.Label(self, text=("""     D.O : 
        """), font=LARGE_FONT)
        label.grid(row=100, column=20, sticky="nsew")

        label = tk.Label(self, text=("""<Sensor reading here>
        """), font=LARGE_FONT)
        label.grid(row=100, column=30, sticky="nsew")

        label = tk.Label(self, text=(""" TEMP : 
        """), font=LARGE_FONT)
        label.grid(row=100, column=40, sticky="nsew")

        label = tk.Label(self, text=("""<Sensor reading here>        
        """), font=LARGE_FONT)
        label.grid(row=100, column=50, sticky="nsew") 

        # Reading data from the arduino

        def DataRead():
            msg = arduinoData.read(arduinoData.inWaiting()) # read everything in the input buffer
            print ("Message from arduino: ")
            print (msg)

        button1 = ttk.Button(self, text="Print arduino data",
                            command=lambda: DataRead())
        button1.grid()

        #Go to Page1 button
        button1 = ttk.Button(self, text="Page1",
                            command=lambda: controller.show_frame(Page1))
        button1.grid(row=100, column=60, sticky="nsew")