Python Forum
[Tkinter] Change property of custom Object
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Change property of custom Object
#1
Hello,

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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Tkinter custom widget styling and creating custom theme karolp 6 4,744 May-06-2020, 06:11 PM
Last Post: karolp
  [Kivy] Kivy property (in .kv) loses binding to a variable (in .py) j.crater 3 5,091 Aug-14-2018, 12:37 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020