Tkinter scrollbar for frame in a Frame - python-3.x

I'm creating a dynamic container that can change between frames. In one of the frames I have a list of values that I need to scroll through because it is so long. However I cannot get the scrollbar to work with the canvas and frame set up.
i have tried using Listbox and this works but does not give me the control over the displays that I am looking for. I want to be able to configure the names of the tag and then to the right the value.
#!Python
import matplotlib
matplotlib.use("TkAgg")
from matplotlib import style
import tkinter as tk
from tkinter import *
from YahooParser import Yahoo_Parser
TITLE_FONT = ("Helvetica", 10, "bold")
LARG_FONT = ("Helvetica", 12)
NORM_FONT = ("Helvetica", 10)
AIR_FONT = ("Arial", 10)
SMALL_FONT = ("Helvetica", 8)
style.use("ggplot")
#style.use("ggplot")
Gray = "#%02x%02x%02x" % (85, 85, 85)
Wight ="#%02x%02x%02x" % (220, 220, 220)
class Midas_Screen(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
# Title
tk.Tk.wm_title(self, "Midas Program")
tk.Tk.geometry(self,"500x400")
#tk.Tk.configure(self, background='black')
# This set the seting for the container
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 = {}
# Makes all the frames and stores them
for F in (HomePage,):
# You pass the container to your page function. this makes the frame
frame = F(container, self)
# this aligns the frame "nsew" = North, South etc
frame.grid(row=0, column=0, sticky="nsew")
# This uses the function as a key in the dic
self.frames[F] = frame
self.show_frame(HomePage)
def show_frame(self, key):
frame = self.frames[key]
frame.tkraise()
class HomePage(tk.Frame):
def __init__(self, perent, controller):
self.yp = Yahoo_Parser()
self.names = []
self.values = {}
for tag in self.yp.values_sum:
self.names.append(tag[0])
for tag in self.yp.values_sta:
self.names.append(tag[0])
for tag in self.names:
self.values[tag]='0'
tk.Frame.__init__(self, perent)
frame = Frame(perent)
frame.grid(row=1, column=1)
canvas = Canvas(frame)
canvas.configure(scrollregion=(0,0,500,500), width=200, height=200)
myscrollbar = Scrollbar(frame, orient="vertical")
myscrollbar.grid(row=1, column=2, sticky="ns")
myscrollbar.config(command=canvas.yview)
canvas.config(yscrollcommand=myscrollbar.set)
R = 1
for key in self.values:
label = tk.Label(canvas, text=key + ':', font=AIR_FONT, bg=Gray, fg=Wight, borderwidth=0,
relief="solid")
value = tk.Label(canvas, text=self.values[key], font=AIR_FONT, bg=Gray, fg=Wight, borderwidth=0,
relief="solid")
label.grid(row=R, column=1, sticky="nsew")
value.grid(row=R, column=2, sticky="nsew")
R += 1
canvas.grid(row=1, column=1)
app = Midas_Screen()
app.mainloop()

The canvas can't scroll things added to the canvas with grid. The most common solution is to add a frame to the canvas with create_window, and then adding the labels to the frame.
See Adding a scrollbar to a group of widgets in Tkinter

So i made a few changes thanks and got it working :)
Bye using pack as you sugeted it works
#!Python
import matplotlib
matplotlib.use("TkAgg")
from matplotlib import style
import tkinter as tk
from tkinter import *
from YahooParser import Yahoo_Parser
TITLE_FONT = ("Helvetica", 10, "bold")
LARG_FONT = ("Helvetica", 12)
NORM_FONT = ("Helvetica", 10)
AIR_FONT = ("Arial", 10)
SMALL_FONT = ("Helvetica", 8)
style.use("ggplot")
#style.use("ggplot")
Gray = "#%02x%02x%02x" % (85, 85, 85)
Wight ="#%02x%02x%02x" % (220, 220, 220)
class Midas_Screen(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
# Title
tk.Tk.wm_title(self, "Midas Program")
tk.Tk.geometry(self,"500x400")
#tk.Tk.configure(self, background='black')
# This set the seting for the container
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 = {}
# Makes all the frames and stores them
for F in (HomePage,):
# You pass the container to your page function. this makes the frame
frame = F(container, self)
# this aligns the frame "nsew" = North, South etc
frame.grid(row=1, column=1, sticky="nsew")
# This uses the function as a key in the dic
self.frames[F] = frame
self.show_frame(HomePage)
def show_frame(self, key):
frame = self.frames[key]
frame.tkraise()
class HomePage(tk.Frame):
def __init__(self, perent, controller):
self.values = {}
for tag in range(20):
self.values['Text'+str(tag)+':']='0'
tk.Frame.__init__(self, perent)
def myfunction(event):
canvas.configure(scrollregion=canvas.bbox("all"), width=200, height=200)
canvas = Canvas(perent)
frame = Frame(canvas)
myscrollbar = Scrollbar(frame, orient="vertical", command=canvas.yview)
canvas.config(yscrollcommand=myscrollbar.set)
myscrollbar.pack(side=RIGHT, fill=Y)# sticky="ns")
canvas.grid(row=0, column=0, sticky="nw")
#canvas.pack(side=LEFT)
canvas.create_window((0, 0), window=frame, anchor='nw')
R = 1
for key in self.values:
row = Frame(frame)
label = tk.Label(row, text=key + ':', font=AIR_FONT, bg=Gray, fg=Wight, borderwidth=0,
relief="solid")
value = tk.Label(row, text=self.values[key], font=AIR_FONT, bg=Gray, fg=Wight, borderwidth=0,
relief="solid")
label.pack(side=LEFT, fill=X)
value.pack(side=LEFT,fill=X)
row.pack(side=TOP, fill=X)
R += 1
frame.bind("<Configure>", myfunction)
app = Midas_Screen()
app.mainloop()

Related

How to Write Data to a File and Plot that File in TK LIVE

I have a sensor that is measuring temperature every second and i'm writing that data to a text file (.txt). I want to have a plot that updates AS the data is written to the file - a live plotter if you will. I have the majority of the framework written to plot the data and have a plot in the GUI that i'm still working on. That code is attached. As it is now, I can execute the code and open up the plotter. As I type data into the file manually and save it, the plot updates. But like I said, i'm looking to have it do that without me opening the file and manually saving it. The sensor would write to the file each second and the plot would just automatically update. In lieu of the sensor code, i've put in a rough skeleton set of code where the sensor code will go.
import matplotlib
matplotlib.use("TkAgg")
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2Tk
from matplotlib.figure import Figure
import matplotlib.animation as animation
from matplotlib import style
from time import sleep
import tkinter as tk
from tkinter import ttk
LARGE_FONT= ("Verdana", 12)
style.use("ggplot")
f = Figure(figsize=(5,5), dpi=100)
a = f.add_subplot(111)
# =============================================================================
# SENSOR DATA INPUT GOES HERE.
# x = random.random()
# y = random.random()
# f = "test_data.txt"
# f.open()
# f.write("test_data.txt,"a") #write to the file in x y format, no comma in between as the
deliniator is a space.
# =============================================================================
def animate(i):
pullData = open("test_data.txt","r").read()
dataList = pullData.split('\n')
xList = []
yList = []
for eachLine in dataList:
if len(eachLine) > 1:
x, y = eachLine.split(' ')
xList.append(float(x)) #int(x)
yList.append(float(y)) #int(y)
a.clear()
a.plot(xList, yList)
class Data_Acq(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
# tk.Tk.iconbitmap(self, default="clienticon.ico")
tk.Tk.wm_title(self, "Data Acquisition")
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,PageThree):
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="Experiment Alpha", font=LARGE_FONT)
label.pack(pady=10,padx=10)
#button = ttk.Button(self, text="Visit Page 1",
# command=lambda: controller.show_frame(PageOne))
#button.pack()
#button2 = ttk.Button(self, text="Visit Page 2",
# command=lambda: controller.show_frame(PageTwo))
#button2.pack()
button3 = ttk.Button(self, text="Graph Page",
command=lambda: controller.show_frame(PageThree))
button3.pack()
class PageThree(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
label = tk.Label(self, text="Graph Page!", font=LARGE_FONT)
label.pack(pady=10,padx=10)
button1 = ttk.Button(self, text="Back to Home",
command=lambda: controller.show_frame(StartPage))
button1.pack()
canvas = FigureCanvasTkAgg(f, self)
canvas.draw()
canvas.get_tk_widget().pack(side=tk.BOTTOM, fill=tk.BOTH, expand=True)
toolbar = NavigationToolbar2Tk(canvas, self)
toolbar.update()
canvas._tkcanvas.pack(side=tk.TOP, fill=tk.BOTH, expand=True)
app = Data_Acq()
ani = animation.FuncAnimation(f, animate, interval=500)
app.mainloop()
So again, as I enter data into the text file in this format:
1 22.0
2 33.1
3 33.0
4 33.5
5 41.2
and hit save on each entry, it updates the graph.

How to make a frame within a canvas take up the entire space?

I'm trying to make the self.frame widget fill the entire canvas. I'm new to canvas so I'm lost, this was my last failed attempt. I don't know what I'm missing. The code is executable, thank you very much for any help.
from tkinter import *
class Example(Frame):
def __init__(self, master, x=None, y=None, *args, **kwargs):
super().__init__(master, *args, kwargs)
self.lblframe = LabelFrame(self, text='Ajustes 0', bg='#2b313c', fg='green2', cursor='arrow')
self.lblframe .pack(side='left', fill='both', expand=True, padx=(10,5), pady=(0,10))
self.canvas = Canvas(self.lblframe, borderwidth=0, bg='red', width=x, height=100, bd=0, highlightthickness=0)
self.canvas .pack(side="left", fill='x', expand=True)
self.scrolly = Scrollbar(self.lblframe, orient="vertical", command=self.canvas.yview)
self.scrolly .pack(side="right", fill="y")
self.frame = Frame(self.canvas, bg='#2b313c', width=x, height=100)
self.frame .pack(fill='both', expand=True)
self.canvas .config(yscrollcommand=self.scrolly.set)
self.canvas .bind("<Configure>", lambda e: self.canvas.configure(scrollregion=self.canvas.bbox('all')))
self.canvas .create_window((0,0), window=self.frame, anchor="nw")
#---loop----
for i in range(8):
label = Label(self.frame, text='number : %s' % i, font=('Calibri',9,'bold'), bg='#2b313c', fg='white', bd=0)
label .grid(column=0, row=i, padx= (10,5), pady=(0,0), sticky='w')
root = Tk()
root .geometry('300x150')
frame = Example(root, 200, 100).pack()
root.mainloop()
You can resize the frame inside the callback of <Configure> event of the canvas:
class Example(Frame):
def __init__(self, master, x=None, y=None, *args, **kwargs):
...
self.canvas .bind("<Configure>", self.on_canvas_resized)
# save the frame item ID
self.frame_id = self.canvas .create_window((0,0), window=self.frame, anchor="nw")
...
def on_canvas_resized(self, event):
w = max(event.width, self.frame.winfo_width())
h = max(event.height, self.frame.winfo_height())
# resize the frame
self.canvas.itemconfig(self.frame_id, width=w, height=h)
self.canvas.configure(scrollregion=self.canvas.bbox('all'))
...

how can i print the entry i took in one frame in another frame

I have built my first few scripts with a nice little GUI on them, as the tutorials have shown me, but none of them address what to do for a little more complex program.
I want to print the values entered in InputPage in second_page.when I try to run my program every frame is getting ready even before entering my input.Here I tried to print the first entry in second_page frame by using a variable named "alpha" .How can I deal with this?
from tkinter import *
from tkinter import ttk
LARGE_FRONT=("Verdana",12)
class simmulator(Tk):
def __init__(self, *args, **kwargs):
Tk.__init__(self, *args, **kwargs)
container = 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 (InputPage,second_page):
frame = F(container, self)
self.frames[F] = frame
frame.grid(row=0, column=0, sticky="nsew")
self.show_frame(InputPage)
def show_frame(self, cont):
frame = self.frames[cont]
frame.tkraise()
def get_page(self, page_class):
return self.frames[page_class]
class InputPage(Frame):
def __init__(self, parent, controller):
self.controller = controller
Frame.__init__(self,parent)
label = Label(self, text="simmulator",font=LARGE_FRONT)
label.grid(row=0, column=0, sticky ='n', columnspan =2)
# i brought your variable in the class for example sake
namesInput = ["Na:", "Nd:", "Temp(t):"]
self.entryWidgets = [] # we want to call this in another function so we assign it as self.variableName
labelWidgets = []
self.alpha = None
#LOOP TO CREATE WIDGETS
for i in range(0, len(namesInput)):
labelWidgets.append(Label(self, text = namesInput[i]))
self.entryWidgets.append(Entry(self))
labelWidgets[-1].grid(row= i+1, column =0, sticky='e')
self.entryWidgets[-1].grid(row= i+1, column = 1, sticky='w')
submit = ttk.Button(self, text = "Submit", command = lambda:[self.push_retrieve_solutions(),controller.show_frame(second_page)])
submit.grid(row = 6, column =0, columnspan =2)
def getEntries(self):
results = []
for x in self.entryWidgets: # i.e for each widget in entryWidget list
results.append(x.get())
self.alpha = results[0]
return results
def push_retrieve_solutions(self):
print(self.getEntries())
class second_page(Frame):
def __init__(self, parent, controller):
self.controller = controller
Frame.__init__(self,parent)
label = Label(self, text="Parameter",font=LARGE_FRONT)
label.grid(row=0, column=0, sticky ='n', columnspan =2)
ctrler = self.controller.get_page(InputPage)
label1 = Label(self,text = "Na =")
label1.grid(row= 1, column =1, sticky='e')
fabel1 = Label(self, text = ctrler.alpha)
fabel1.grid(row= 1, column = 2, sticky='w')
app = simmulator()
app.mainloop()

How to update matplotlib embedded into tkinter?

The problem is that I want to draw a plot by clicking on a button but it doesn't work. However, when I call draw from __init__, the plot appears on the screen.
Plotter.py
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from matplotlib.figure import Figure
class Plotter(FigureCanvasTkAgg):
def __init__(self, master):
self.figure = Figure(dpi=100)
super().__init__(self.figure, master=master)
self.axes = self.figure.add_subplot(111)
self.get_tk_widget().grid(column=0, row=0, sticky='nsew')
def draw(self):
self.axes.clear()
x_list = [x for x in range(0, 100)]
y_list = [x^3 for x in x_list]
self.axes.plot(x_list, y_list, color='y')
MainApplication.py
from tkinter import ttk
import tkinter as tk
import plotter
class MainApplication(ttk.Frame):
def __init__(self, master, *args, **kwargs):
super().__init__(root)
self.grid(column=0, row=0, sticky='nsew')
frame = ttk.Frame(self, borderwidth=8)
frame.grid(column=0, row=0, sticky='nsew')
frame.rowconfigure(0, weight=1)
notes = ttk.Notebook(frame)
notes.grid(column=0, row=0, sticky='nsew')
notes.rowconfigure(0, weight=1)
page = ttk.Frame(notes)
notes.add(page, text='Picture')
plot = plotter.Plotter(page)
# plot.draw() # This call updates the plot
input_frame = ttk.Frame(self)
input_frame.grid(column=1, row=0, sticky='nsew')
# this binding doesn't update the plot
button = ttk.Button(input_frame, text='Plot', \
command=lambda: plot.draw())
button.grid(column=0, row=4, columnspan=2, sticky='ew')
root = tk.Tk()
MainApplication(root)
root.mainloop()
Personally I would write this up in a single class so that we can use class attributes and methods to control everything with ease. Also you do not need a lambda here. Just save the reference to the command button and not a lambda call. That said you were also overwriting the draw method of FigureCanvasTkAgg so change the draw() method to something else.
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from matplotlib.figure import Figure
from tkinter import ttk
import tkinter as tk
class MainApplication(tk.Tk):
def __init__(self):
tk.Tk.__init__(self)
notes = ttk.Notebook(self)
notes.grid(column=0, row=0, sticky='nsew')
notes.rowconfigure(0, weight=1)
self.page = ttk.Frame(notes)
notes.add(self.page, text='Picture')
self.plotter()
input_frame = ttk.Frame(self)
input_frame.grid(column=1, row=0, sticky='nsew')
button = ttk.Button(input_frame, text='Plot', command=self.new_draw)
button.grid(column=0, row=4, columnspan=2, sticky='ew')
def plotter(self):
self.figure = Figure(dpi=100)
self.plot_canvas = FigureCanvasTkAgg(self.figure, self.page)
self.axes = self.figure.add_subplot(111)
self.plot_canvas.get_tk_widget().grid(column=0, row=0, sticky='nsew')
def new_draw(self):
self.axes.clear()
x_list = [x for x in range(0, 100)]
y_list = [x^3 for x in x_list]
self.axes.plot(x_list, y_list, color='y')
self.plot_canvas.draw_idle()
MainApplication().mainloop()
You overwrote the canvas' draw method without reimplementing it. But since you do not want to update your plot on every draw-event anyways, I'd suggest to call the method to update the plot differently, e.g. draw_lists. Inside draw_lists you would then need to call the draw method of the canvas (or in this case better draw_idle).
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from matplotlib.figure import Figure
class Plotter(FigureCanvasTkAgg):
def __init__(self, master):
self.figure = Figure(dpi=100)
super().__init__(self.figure, master=master)
self.axes = self.figure.add_subplot(111)
self.get_tk_widget().grid(column=0, row=0, sticky='nsew')
def draw_lists(self):
self.axes.clear()
x_list = [x for x in range(0, 100)]
y_list = [x^3 for x in x_list]
self.axes.plot(x_list, y_list, color='y')
self.draw_idle()
from tkinter import ttk
import tkinter as tk
class MainApplication(ttk.Frame):
def __init__(self, master, *args, **kwargs):
super().__init__(root)
self.grid(column=0, row=0, sticky='nsew')
frame = ttk.Frame(self, borderwidth=8)
frame.grid(column=0, row=0, sticky='nsew')
frame.rowconfigure(0, weight=1)
notes = ttk.Notebook(frame)
notes.grid(column=0, row=0, sticky='nsew')
notes.rowconfigure(0, weight=1)
page = ttk.Frame(notes)
notes.add(page, text='Picture')
plot = Plotter(page)
input_frame = ttk.Frame(self)
input_frame.grid(column=1, row=0, sticky='nsew')
# this binding doesn't update the plot
button = ttk.Button(input_frame, text='Plot', \
command=lambda: plot.draw_lists())
button.grid(column=0, row=4, columnspan=2, sticky='ew')
root = tk.Tk()
MainApplication(root)
root.mainloop()

Tkinter Serial data on multiple pages

I am using Python3 with TKinter and have run into an issue, even after reading the forums and the TKdocs website I am still making no headway. I am receiving temperature readings via my com-port. My program so far has a Start page and a page one with a graph on it that updates with every reading. So the question is how can I print the sensor data on page one as well, I am new to tkinter.
I will post the code below any advice welcome.
import matplotlib
matplotlib.use("TkAgg")
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg,
NavigationToolbar2Tk
from matplotlib.figure import Figure
import matplotlib.animation as animation
from matplotlib import style
import random
import sys
import time
import tkinter as tk
from tkinter import ttk
import matplotlib.pyplot as plt #import matplotlib library
from drawnow import *
import urllib
import json
import serial # import Serial Library
import numpy # Import numpy
import pandas as pd
import numpy as np
LARGE_FONT= ("Verdana", 12)
style.use("ggplot") #ggplot...dark_background
do = []
tempF= []
f = Figure(figsize=(10,6), dpi=100)
a = f.add_subplot(111)
arduinoData = serial.Serial('com3', 115200) #Creating our serial object
def animate(i):
if(arduinoData.inWaiting()>0):
#read serial data
arduinoString = arduinoData.readline()
xList = []
yList = []
#Parse serial data
arduinoString.split()
['', '', '', '', '', '', '', '']
words = arduinoString.split()
reading = words[3]
if words[1] == (b'TEMP') :
print (words[0])
print (words[1])
print (words[3])
tempF.append(reading) #Build our tempF array by appending temp readings
a.clear()
a.plot(*yList, *yList)
title = " D.O : "+str(do) + "\n Temp : " + str(tempF)
a.set_title(title)
arduinoData.flushInput()
arduinoData.flushOutput()
class Application(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
tk.Tk.wm_title(self, "Stylibleue Dashboard")
# the container is where we'll stack a bunch of frames on top each other
container = tk.Frame(self)
container.pack(side="top", fill="both", expand = True)
container.grid_rowconfigure(0, weight=1)
container.grid_columnconfigure(0, weight=1)
#Switch through pages
self.frames = {}
for F in (StartPage, Page1,):
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)
#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")
#Go to Page1 button
button1 = ttk.Button(self, text="Page1",
command=lambda: controller.show_frame(Page1))
button1.grid(row=100, column=60, sticky="nsew")
class Page1(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
label = tk.Label(self, text="Bassin 2!!!", font=LARGE_FONT)
label.pack(pady=10,padx=10)
#Return home button
button1 = ttk.Button(self, text="Back to Home",
command=lambda: controller.show_frame(StartPage))
button1.pack()
#This is the embedded matplotlib graph
canvas = FigureCanvasTkAgg(f, self)
canvas.draw()
canvas.get_tk_widget().pack(side=tk.BOTTOM, fill=tk.BOTH, expand=True)
toolbar = NavigationToolbar2Tk(canvas, self)
toolbar.update()
canvas._tkcanvas.pack(side=tk.TOP, fill=tk.BOTH, expand=True)
app = Application()
ani = animation.FuncAnimation(f, animate, interval=1000)
app.mainloop()
At first I misunderstood the question, so now I am rewriting the answer. If you still have some doubts or this is not what you were expecting, just comment below. I'll try my best to help. Also, I don't have an arduino to check this for.
I have made the following changes to your code:
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")

Resources