Python Forum
Still Stumped - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Still Stumped (/thread-29439.html)



Still Stumped - Milfredo - Sep-02-2020

I have watched a couple of videos and still stumped. The calc_value variable get assigned a number and I print it out and it is fine. But when I try and put it in a dictionary in another function it doesn't show up. Anyway here's code.

# SET  UP CALCULATOR SLIDER TO SET FACTOR WEIGHTS
def get_Caclulator():
	calculator= Toplevel()
	global Calculator_horizontal
	global factornames
	global calc_value
	width_of_window = 300
	height_of_window = 300
	

	screen_width= calculator.winfo_screenwidth()
	screen_height = calculator.winfo_screenheight()
	x_coordinate = (screen_width/2) - (width_of_window/2)
	y_coordinate = (screen_height/2) - (height_of_window/2)
	calculator.geometry("%dx%d+%d+%d" % (width_of_window,height_of_window,x_coordinate,y_coordinate ))
	calculator.iconbitmap("c:/guis/racehorse.ico")
	
	Calculator_horizontal = Scale(calculator, from_= -50, to = 250, length = 200, resolution = 2,orient=HORIZONTAL)
	Calculator_horizontal.place(x=50, y=60)
	
	my_label= Label(calculator, text ="Set Factor Weight", fg= "#104CD6", font = ("sans_serif" , 16)).place(x=50, y=20)

	calc_button = Button(calculator, text = "Save Weight",bg="#E2F07F", width = 15,  command = set_calc_value) 
	calc_button.place(x=90, y=125)
	
def set_calc_value():
	global calc_value
	global factornames
	global factor
	global Factor_ypos
	global calc_valu_pos
	calc_valu_pos += 25
	calc_value = Calculator_horizontal.get()
	calc_value_label=Label(factor_build,text = calc_value, fg="black",font = ("sans_serif" , 14) ).place(x=1000,y=calc_valu_pos)

def set_drfvalue():
	
	get_Caclulator()
	global Factor_ypos
	global calc_value
	Factor_ypos += 25
	a_factorname= Label( factor_build, text ="drf", fg= "black", font = ("sans_serif" , 16)).place(x=750, y= Factor_ypos) 
	factor_list['drf']	= 	calc_value
	print(factor_list['drf'])
	print(calc_value)	
I print calc_value in def set_calc_value(): to check it and it has a value. But when I get to the def set_drfvalue(): it doesn't show a value.

Help please


RE: Still Stumped - bowlofred - Sep-02-2020

This code isn't runnable directly, so it might be something happening in another part of your code.

I do see that your button command (which is run every time the button is pressed) appears to create and place a new Label. I think modifying an existing label would be better.


RE: Still Stumped - Milfredo - Sep-02-2020

Each time the button is clicked in the set_calc_value it puts an entry on the screen below the previous one. The label is modified I thought. Uses same label with a different value. And the button in get_calculator only gets clicked once and then the window is closed until another factor button is clicked which opens the calculator screen again.

The calc_value I am having trouble with only appears in these three functions. no where else in my code.