Dec-17-2020, 10:53 AM
Hello,
In my application I use a customized Widget, developed previously by someone.
Here is the code of this customized widget:
But when I execute setXLabel with a new value for label, nothing changes.
Any advices ?
Thanks.
In my application I use a customized Widget, developed previously by someone.
Here is the code of this customized widget:
from tkinter import * from tkinter.font import Font from datetime import datetime, timedelta from matplotlib import * from matplotlib.figure import Figure from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg import Utils.Constant as Constant from View.Widget.Widget import Widget class ControlGraphWidget(Widget): """description of class""" def __init__(self, parent): Widget.__init__(self, parent) self.createView() self.createPlot() def getTkWidget(self): return self.figure def createView(self): self.frame = Frame(self, background=Constant.White) self.font = Font(family=Constant.FontFamily, size=Constant.FontBigSize) self.frame.pack(side=TOP, fill=BOTH, expand=True) def createPlot(self): self.figure = Figure(figsize=(7,7), dpi=80) self.graph = FigureCanvasTkAgg(self.figure, master=self.frame) self.graph.get_tk_widget().pack(side=TOP, fill=BOTH, expand=True) self.figure.subplots_adjust(left=0.1, right=0.9, top=0.925, bottom=0.1) self.__plot1 = self.figure.add_subplot(1, 1, 1) self.__plot1.set_facecolor(Constant.DarkGrey) self.__plot2 = self.__plot1.twinx() def setXLabel(self, label, color): self.__plot1.set_xlabel(label, color=color) self.__plot1.tick_params(axis='x', labelcolor=color) def setY1Label(self, label, color): self.__plot1.set_ylabel(label, color=color) self.__plot1.tick_params(axis='y', labelcolor=color) def setY2Label(self, label, color): self.__plot2.set_ylabel(label, color=color) self.__plot2.tick_params(axis='y', labelcolor=color) def clear(self): self.__plot1.clear() self.__plot2.clear() def plot(self, xValues, yValues, color, plotNumber): if plotNumber == 1: self.__plot1.plot(xValues, yValues, visible = True, linewidth=1, color=color) self.__plot1.xaxis.set_major_formatter(ticker.FormatStrFormatter("%d")) self.__plot1.yaxis.set_major_formatter(ticker.FormatStrFormatter("%d")) elif plotNumber == 2: self.__plot2.plot(xValues, yValues, visible = True, linewidth=1, color=color) self.__plot2.xaxis.set_major_formatter(ticker.FormatStrFormatter("%d")) self.__plot2.yaxis.set_major_formatter(ticker.FormatStrFormatter("%d"))When application runs, sometimes I need to modify XLabel according to some conditions.
But when I execute setXLabel with a new value for label, nothing changes.
Any advices ?
Thanks.