Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Still Stumped
#1
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
Reply
#2
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.
Reply
#3
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Stumped by my own code (ratio & epoch-time calculation). MvGulik 2 2,088 Dec-30-2020, 12:04 AM
Last Post: MvGulik
  Really stumped now Milfredo 7 3,008 Sep-17-2020, 06:18 AM
Last Post: Milfredo
  attribute error stumped on how to fix it. hank4eva 7 4,596 Aug-11-2020, 04:47 AM
Last Post: hank4eva

Forum Jump:

User Panel Messages

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