How I wrote a youtube graphing visualizing and you can too.(part 2)

How I wrote a youtube graphing visualizing and you can too.(part 2)

import numpy as np


First import numpy as np, which uses the 'ndarray' data structure.

clear_Button = Button(window, text = 'Remove the graph',command=clearClear)

In this line where I have set a variable named "clear_Button" to a Button constructor passing in the tk instance, which in this example is set to a variable named "window". Then the second parameter is to set the text of the button, the third parameter is setting the command parameter to a function that will be called when the button is pressed, which in my example is called "clearClear".

display_Label = Label(window,text=parsingValues, width=100, height = 5, fg = "red")

This line sets a variable named "display_Label" to a Label constructor for a Label object that takes a tk instance as its first parameter, the text for this label is set to a variable named "parsingValues" and I will give further information on this variable soon, the third and fourth parameters are width and height, and fg is used to set the color of the text.

var =[]

This is a variable named "var", which is set to an array, and will be used later.

typeofGraphChoice = StringVar()

This line sets the variable named "typeofGraphChoice" to a StringVar object by using the "StringVar()" constructor from the tkinter library. The tkinter allows for certain types, but you can get and set the object just like you do with getters and setters in java. For example, every StringVar() object will have a set() method and get() method.

typeofGraphChoice.set("Select a type of graph")

In this line, set the StringVar() object by using the set method and passing in some text.

xVar = StringVar()

Creating a StringVar object

yVar = StringVar()

Again, creating a StringVar object

xVar.set("Set the variable for X")

Setting the text of the StringVar object

yVar.set("Set the variable for Y")

Setting the text of the StringVar object


drop = OptionMenu(window,typeofGraphChoice,"Bar","Horizontal Bar Graph", "line graph", "scatter plot")

In this next line, I set the variable named "drop" to an Option Menu object by using the OptionMenu constructor and passing a tk object instance, which is "window". The second parameter takes the default state of the drop-down menu and is "select a graph choice" in my example or "typeofGraphChoice", which is what the variable is currently set to, and the rest of the following are the choices that will display when the drop-down menu is clicked.

dropDownVarAssX = OptionMenu(window,xVar, "Names", "Comments", "Views", "Likes" )

This line sets a variable named "dropDownVarAssX" to another Option Menu object by using the OptionMenu constructor. So, obviously same thing as before passing an instance of TK(). The second parameter is taking the default, which in my case is "xVar" which is set to "set the x variable", and the following are the options that will display when the options menu is clicked.

dropDownVarAssY = OptionMenu(window,yVar, "Names", "Comments", "Views", "Likes" )

This line sets a variable named "dropDownVarAssY" to another Option Menu object by using the OptionMenu constructor.. The second parameter is taking the default, which in my case is "yVar" which is set to "set the y variable", and the following are the options that will display when the options menu is clicked.

.... to be continued

要查看或添加评论,请登录

Christofer P. P.的更多文章

社区洞察

其他会员也浏览了