悬停时如何显示饼图的类别?
How to show categories of pie chart when hovered over?
如何通过 hoverlabel 类型的东西来识别每一块馅饼?这个馅饼是平分的,但我想要它,所以当我将鼠标悬停在一个部分上时,它会告诉我该部分代表什么。即鼠标悬停在知识切片上,显示"Knowledge Category".
knowledge_slice1 = (k_weighting1/100) * 360
thinking_slice1 = (t_weighting1/100) * 360
communication_slice1 = (c_weighting1/100) * 360
application_slice1 = (a_weighting1/100) * 360
course1_pie = Canvas(assessmentsframe1, width=255, height=255, bg = 'white')
course1_pie.create_arc((5, 5, 250, 250), fill = "#FFFFAA",
start= 0,
extent = knowledge_slice1)
course1_pie.create_arc((5, 5, 250, 250), fill = "#C0FEA4",
start= knowledge_slice1,
extent = thinking_slice1)
course1_pie.create_arc((5, 5, 250, 250), fill = "#AFAFFF",
start= knowledge_slice1 + thinking_slice1,
extent = communication_slice1)
course1_pie.create_arc((5, 5, 250, 250), fill = "#FFD490",
start= knowledge_slice1 + thinking_slice1 + communication_slice1,
extent =application_slice1)
我本人是 python 和 Tkinter 的新手,但您似乎可能想要使用 和 事件绑定。例如,这对我有用:
master=Tk()
knowledge_slice1 = (40.0/100) * 360
thinking_slice1 = (30.0/100) * 360
communication_slice1 = (20.0/100) * 360
application_slice1 = (10.0/100) * 360
course1_pie = Canvas(master, width=265, height=265, bg = 'white')
course1_pie.pack()
knowarc=course1_pie.create_arc((5, 5, 250, 250), fill = "#FFFFAA",
start= 0,
extent = knowledge_slice1)
thinkarc=course1_pie.create_arc((5, 5, 250, 250), fill = "#C0FEA4",
start= knowledge_slice1,
extent = thinking_slice1)
commarc=course1_pie.create_arc((5, 5, 250, 250), fill = "#AFAFFF",
start= knowledge_slice1 + thinking_slice1,
extent = communication_slice1)
apparc=course1_pie.create_arc((5, 5, 250, 250), fill = "#FFD490",
start= knowledge_slice1 + thinking_slice1 + communication_slice1,
extent =application_slice1)
hover_text=course1_pie.create_text((125,260),text="")
def know_enter(event):
course1_pie.itemconfig(hover_text,text="Knowledge Category")
def think_enter(event):
course1_pie.itemconfig(hover_text,text="Thinking Category")
def comm_enter(event):
course1_pie.itemconfig(hover_text,text="Communication Category")
def app_enter(event):
course1_pie.itemconfig(hover_text,text="Application Category")
def any_leave(event):
course1_pie.itemconfig(hover_text,text="")
course1_pie.tag_bind(knowarc,'<Enter>',know_enter)
course1_pie.tag_bind(knowarc,'<Leave>',any_leave)
course1_pie.tag_bind(thinkarc,'<Enter>',think_enter)
course1_pie.tag_bind(thinkarc,'<Leave>',any_leave)
course1_pie.tag_bind(commarc,'<Enter>',comm_enter)
course1_pie.tag_bind(commarc,'<Leave>',any_leave)
course1_pie.tag_bind(apparc,'<Enter>',app_enter)
course1_pie.tag_bind(apparc,'<Leave>',any_leave)
如何通过 hoverlabel 类型的东西来识别每一块馅饼?这个馅饼是平分的,但我想要它,所以当我将鼠标悬停在一个部分上时,它会告诉我该部分代表什么。即鼠标悬停在知识切片上,显示"Knowledge Category".
knowledge_slice1 = (k_weighting1/100) * 360
thinking_slice1 = (t_weighting1/100) * 360
communication_slice1 = (c_weighting1/100) * 360
application_slice1 = (a_weighting1/100) * 360
course1_pie = Canvas(assessmentsframe1, width=255, height=255, bg = 'white')
course1_pie.create_arc((5, 5, 250, 250), fill = "#FFFFAA",
start= 0,
extent = knowledge_slice1)
course1_pie.create_arc((5, 5, 250, 250), fill = "#C0FEA4",
start= knowledge_slice1,
extent = thinking_slice1)
course1_pie.create_arc((5, 5, 250, 250), fill = "#AFAFFF",
start= knowledge_slice1 + thinking_slice1,
extent = communication_slice1)
course1_pie.create_arc((5, 5, 250, 250), fill = "#FFD490",
start= knowledge_slice1 + thinking_slice1 + communication_slice1,
extent =application_slice1)
我本人是 python 和 Tkinter 的新手,但您似乎可能想要使用
master=Tk()
knowledge_slice1 = (40.0/100) * 360
thinking_slice1 = (30.0/100) * 360
communication_slice1 = (20.0/100) * 360
application_slice1 = (10.0/100) * 360
course1_pie = Canvas(master, width=265, height=265, bg = 'white')
course1_pie.pack()
knowarc=course1_pie.create_arc((5, 5, 250, 250), fill = "#FFFFAA",
start= 0,
extent = knowledge_slice1)
thinkarc=course1_pie.create_arc((5, 5, 250, 250), fill = "#C0FEA4",
start= knowledge_slice1,
extent = thinking_slice1)
commarc=course1_pie.create_arc((5, 5, 250, 250), fill = "#AFAFFF",
start= knowledge_slice1 + thinking_slice1,
extent = communication_slice1)
apparc=course1_pie.create_arc((5, 5, 250, 250), fill = "#FFD490",
start= knowledge_slice1 + thinking_slice1 + communication_slice1,
extent =application_slice1)
hover_text=course1_pie.create_text((125,260),text="")
def know_enter(event):
course1_pie.itemconfig(hover_text,text="Knowledge Category")
def think_enter(event):
course1_pie.itemconfig(hover_text,text="Thinking Category")
def comm_enter(event):
course1_pie.itemconfig(hover_text,text="Communication Category")
def app_enter(event):
course1_pie.itemconfig(hover_text,text="Application Category")
def any_leave(event):
course1_pie.itemconfig(hover_text,text="")
course1_pie.tag_bind(knowarc,'<Enter>',know_enter)
course1_pie.tag_bind(knowarc,'<Leave>',any_leave)
course1_pie.tag_bind(thinkarc,'<Enter>',think_enter)
course1_pie.tag_bind(thinkarc,'<Leave>',any_leave)
course1_pie.tag_bind(commarc,'<Enter>',comm_enter)
course1_pie.tag_bind(commarc,'<Leave>',any_leave)
course1_pie.tag_bind(apparc,'<Enter>',app_enter)
course1_pie.tag_bind(apparc,'<Leave>',any_leave)