I have finally managed to find the specific code to deal with my request. I add it below in case someone else finds it also usefull.
get_ipython().magic('reset -sf')
import tkinter as tk
from matplotlib.backends.backend_tkagg import (
FigureCanvasTkAgg, NavigationToolbar2Tk)
from matplotlib.figure import Figure
from tkinter import *
import pandas as pd
root= tk.Tk()
main_fig = Figure(figsize=(5,4), dpi=100)
axis = main_fig.add_subplot(111)
axis.plot(-10,'o-', label='class1',color='w')
axis.plot(-10,'o-', label='class2',color='b')
axis.plot(-10,'o-', label='class3',color='r')
axis.legend(loc='best', fancybox=True, framealpha=0.5)
axis.set_xlabel('x')
axis.set_ylabel('y')
axis.set_title('title')
# Set the limit for each axis
axis.set_xlim([0, 100])
axis.set_ylim([0, 100])
axis.grid()
axis.axvspan(0, 33, 0, 0.33, color = "powderblue", alpha=1,zorder=1)
axis.axvspan(33, 66, 0, 0.33, color = "palegreen", alpha=1,zorder=1)
axis.axvspan(0, 66, 0.33, 0.66, color = "palegreen", alpha=1,zorder=1)
axis.axvspan(66, 100, 0, 0.66, color = "darkgreen", alpha=1,zorder=1)
axis.axvspan(0, 100, 0.66, 1, color = "darkgreen", alpha=1,zorder=1)
# Create figure in the canvas
scatter = FigureCanvasTkAgg(main_fig, master = root)
toolbar = NavigationToolbar2Tk(scatter, root)
toolbar.update()
# Create main canvas
canvas1 = tk.Canvas(root, width = 800, height = 500)
canvas1.pack()
label0 = tk.Label(root, text='Graphical interface',font='bold')
label0.config(font=('Arial', 12))
canvas1.create_window(400, 25, window=label0)
# Give name of activity - text label
label_activity = tk.Label(root,text = "item")
label_activity.pack()
canvas1.create_window(400, 80, window=label_activity)
# Give entry 1
activity_name = tk.Entry (root,bd = 2)
activity_name.pack()
canvas1.create_window(400, 110, window=activity_name)
# Give name component 1
label_Innovation_tech = tk.Label(root,text = "class1")
label_Innovation_tech.pack()
canvas1.create_window(400, 150, window=label_Innovation_tech)
# Insert slider 1
myslider_Innovation_tech = Scale(root, from_=0, to=100, orient=HORIZONTAL, tickinterval=50)
canvas1.create_window(400, 190, window=myslider_Innovation_tech)
# Give name component 2
label_Innovation_market = tk.Label(root,text = "class2")
label_Innovation_market.pack()
canvas1.create_window(400, 210, window=label_Innovation_market)
# Insert slider 2
myslider_Innovation_market = Scale(root, from_=0, to=100, orient=HORIZONTAL, tickinterval=50)
canvas1.create_window(400, 250, window=myslider_Innovation_market)
# Give name component 3
label_maturity_level = tk.Label(root,text = "class3")
label_maturity_level.pack(pady=30)
canvas1.create_window(400, 290, window=label_maturity_level)
# Insert dropmenu
clicked= tk.StringVar(root) #Access the Menu Widget using StringVar function
clicked.set('Click to see dropmenu')
maturity_menu = OptionMenu(root, clicked, "type1","type2","type3")
maturity_menu.pack()
canvas1.create_window(400, 320, window=maturity_menu)
def add_to_chart():
activity_name_text = activity_name.get()
x1 = float(myslider_Innovation_tech.get())
x2 = float(myslider_Innovation_market.get())
maturity_lvl = clicked.get()
# Set legend color
color = 'r'
if maturity_lvl == "class1":
color = 'w'
elif maturity_lvl == "class2":
color = 'b'
elif maturity_lvl == "class3":
color = 'r'
axis.scatter(x1,x2, color = color,zorder=3)
axis.annotate('%s' % (activity_name_text), xy=(x1, x2), xytext=(0, -10),textcoords='offset points', ha='center', va='top')
scatter.get_tk_widget().pack(side=tk.BOTTOM, fill=tk.BOTH) # start plotting window only after first Add_to_chart click
scatter.draw()
button1 = tk.Button (root, text='Add in Chart',command=add_to_chart, bg='darkgreen',fg = 'white', font=('Arial', 10, 'bold'))
canvas1.create_window(400, 430, window=button1)
button2 = tk.Button (root, text='Exit Application', command=root.destroy, bg='lightsteelblue2', font=('Arial', 10, 'bold'))
canvas1.create_window(400, 460, window=button2)
root.mainloop()