*Hello! Im beginner at Tkinter and this is my 1st project. I want make programm that calculate resistor value from colors, but i can`t get variables out of functions. Here you can see all code:*
#fails 251.py import Tkinter as tk from Tkinter import * import math root=tk.Tk() root.title("rezistoru aprekins") w= tk.Canvas(root, width=700, height=550, bg="#abc") w.pack() linija = w.create_line(10, 100, 375, 100, width='10',fill='black') linija = w.create_line(100, 50, 100, 150, width='50',fill='#FFCC99') linija = w.create_line(300, 50, 300, 150, width='50',fill='#FFCC99') linija = w.create_line(75, 100, 300, 100, width='80',fill='#FFCC99') linija = w.create_line(110, 50, 110, 150, width='15',fill='red') linija = w.create_line(150, 60, 150, 140, width='15',fill='red') linija = w.create_line(180, 60, 180, 140, width='15',fill='red') linija = w.create_line(260, 60, 260, 140, width='15',fill='red') linija = w.create_line(30, 190, 110, 155, width='1',fill='black') linija = w.create_line(150, 148, 200, 190, width='1',fill='black') linija = w.create_line(180, 145, 350, 190, width='1',fill='black') linija = w.create_line(260, 145, 500, 190, width='1',fill='black') #x1=tk.IntVar() #x2=tk.IntVar() def fun2(): linija = w.create_line(110, 50, 110, 150, width='15',fill='black') x=00 w.itemconfig(t2,text=x) def fun3(): linija = w.create_line(110, 50, 110, 150, width='15',fill='brown') x=10 w.itemconfig(t2,text=x) def fun4(): linija = w.create_line(110, 50, 110, 150, width='15',fill='red') x=20 w.itemconfig(t2,text=x) def fun5(): linija = w.create_line(110, 50, 110, 150, width='15',fill='orange') x=30 w.itemconfig(t2,text=x) def fun6(): linija = w.create_line(110, 50, 110, 150, width='15',fill='yellow') x=40 w.itemconfig(t2,text=x) def fun7(): linija = w.create_line(110, 50, 110, 150, width='15',fill='green') x=50 w.itemconfig(t2,text=x) def fun8(): linija = w.create_line(110, 50, 110, 150, width='15',fill='blue') x=60 w.itemconfig(t2,text=x) def fun9(): linija = w.create_line(110, 50, 110, 150, width='15',fill='purple') x=70 w.itemconfig(t2,text=x) def fun10(): linija = w.create_line(110, 50, 110, 150, width='15',fill='gray') x=80 w.itemconfig(t2,text=x) def fun11(): linija = w.create_line(110, 50, 110, 150, width='15',fill='white') x=90 w.itemconfig(t2,text=x) def fun21(): linija = w.create_line(150, 60, 150, 140, width='15',fill='black') x1=00 w.itemconfig(t3,text=x1) def fun31(): linija = w.create_line(150, 60, 150, 140, width='15',fill='brown') x1=1 w.itemconfig(t3,text=x1) def fun41(): linija = w.create_line(150, 60, 150, 140, width='15',fill='red') x1=2 w.itemconfig(t3,text=x1) def fun51(): linija = w.create_line(150, 60, 150, 140, width='15',fill='orange') x1=3 w.itemconfig(t3,text=x1) def fun61(): linija = w.create_line(150, 60, 150, 140, width='15',fill='yellow') x1=4 w.itemconfig(t3,text=x1) def fun71(): linija = w.create_line(150, 60, 150, 140, width='15',fill='green') x1=5 w.itemconfig(t3,text=x1) def fun81(): linija = w.create_line(150, 60, 150, 140, width='15',fill='blue') x1=6 w.itemconfig(t3,text=x1) def fun91(): linija = w.create_line(150, 60, 150, 140, width='15',fill='purple') x1=7 w.itemconfig(t3,text=x1) def fun101(): linija = w.create_line(150, 60, 150, 140, width='15',fill='gray') x1=8 w.itemconfig(t3,text=x1) def fun111(): linija = w.create_line(150, 60, 150, 140, width='15',fill='white') x1=9 w.itemconfig(t3,text=x1) #3linija def fun22(): linija = w.create_line(180, 60, 180, 140, width='15',fill='black') x2=1 w.itemconfig(t4,text=x2) def fun32(): linija = w.create_line(180, 60, 180, 140, width='15',fill='brown') x2=10 w.itemconfig(t4,text=x2) def fun42(): linija = w.create_line(180, 60, 180, 140, width='15',fill='red') x2=100 w.itemconfig(t4,text=x2) def fun52(): linija = w.create_line(180, 60, 180, 140, width='15',fill='orange') x2=1000 w.itemconfig(t4,text=x2) def fun62(): linija = w.create_line(180, 60, 180, 140, width='15',fill='yellow') x2=10000 w.itemconfig(t4,text=x2) def fun72(): linija = w.create_line(180, 60, 180, 140, width='15',fill='green') x2=100000 w.itemconfig(t4,text=x2) def fun82(): linija = w.create_line(180, 60, 180, 140, width='15',fill='blue') x2=1000000 w.itemconfig(t4,text=x2) def fun92(): linija = w.create_line(180, 60, 180, 140, width='15',fill='purple') x2=10000000 w.itemconfig(t4,text=x2) def fun102(): linija = w.create_line(180, 60, 180, 140, width='15',fill='#EAC117') x2=0.01 w.itemconfig(t4,text=x2) def fun112(): linija = w.create_line(180, 60, 180, 140, width='15',fill='#C0C0C0') x2=0.1 w.itemconfig(t4,text=x2) #4linija def fun23(): linija = w.create_line(260, 60, 260, 140, width='15',fill='brown') x3=1 w.itemconfig(t5,text=x3) def fun33(): linija = w.create_line(260, 60, 260, 140, width='15',fill='red') x3=2 w.itemconfig(t5,text=x3) def fun43(): linija = w.create_line(260, 60, 260, 140, width='15',fill='#EAC117') x3=5 w.itemconfig(t5,text=x3) def fun53(): linija = w.create_line(260, 60, 260, 140, width='15',fill='#C0C0C0') x3=10 w.itemconfig(t5,text=x3) t1 = w.create_text(1, 200, text="first color: ",font="Courier 10 bold ", fill ="black",anchor='w') b1=tk.Button(root, text="black ", command=fun2,width=8) b1.pack() b1.place(x=5 ,y=220) b2=tk.Button(root, text="brown", command=fun3,width=8) b2.pack() b2.place(x=5 ,y=250) b3=tk.Button(root, text="red ", command=fun4,width=8) b3.pack() b3.place(x=5 ,y=280) b4=tk.Button(root, text="orange", command=fun5,width=8) b4.pack() b4.place(x=5 ,y=310) b5=tk.Button(root, text="yellow", command=fun6,width=8) b5.pack() b5.place(x=5 ,y=340) b6=tk.Button(root, text="green", command=fun7,width=8) b6.pack() b6.place(x=5 ,y=370) b7=tk.Button(root, text="blue", command=fun8,width=8) b7.pack() b7.place(x=5 ,y=400) b8=tk.Button(root, text="purple", command=fun9,width=8) b8.pack() b8.place(x=5 ,y=430) b9=tk.Button(root, text="gray", command=fun10,width=8) b9.pack() b9.place(x=5 ,y=460) b10=tk.Button(root, text="white", command=fun11,width=8) b10.pack() b10.place(x=5 ,y=490) t11 = w.create_text(150, 200, text="second color: ",font="Courier 10 bold ", fill ="black",anchor='w') b11=tk.Button(root, text="black ", command=fun21,width=8) b11.pack() b11.place(x=150 ,y=220) b21=tk.Button(root, text="brown", command=fun31,width=8) b21.pack() b21.place(x=150 ,y=250) b31=tk.Button(root, text="red ", command=fun41,width=8) b31.pack() b31.place(x=150 ,y=280) b41=tk.Button(root, text="orange", command=fun51,width=8) b41.pack() b41.place(x=150 ,y=310) b51=tk.Button(root, text="yellow", command=fun61,width=8) b51.pack() b51.place(x=150 ,y=340) b61=tk.Button(root, text="green", command=fun71,width=8) b61.pack() b61.place(x=150 ,y=370) b71=tk.Button(root, text="blue", command=fun81,width=8) b71.pack() b71.place(x=150 ,y=400) b81=tk.Button(root, text="purple", command=fun91,width=8) b81.pack() b81.place(x=150 ,y=430) b91=tk.Button(root, text="gray", command=fun101,width=8) b91.pack() b91.place(x=150 ,y=460) b101=tk.Button(root, text="white", command=fun111,width=8) b101.pack() b101.place(x=150 ,y=490) t1 = w.create_text(300, 200, text="third color: ",font="Courier 10 bold ", fill ="black",anchor='w') b1=tk.Button(root, text="black ", command=fun22,width=8) b1.pack() b1.place(x=300 ,y=220) b2=tk.Button(root, text="brown", command=fun32,width=8) b2.pack() b2.place(x=300 ,y=250) b3=tk.Button(root, text="red ", command=fun42,width=8) b3.pack() b3.place(x=300 ,y=280) b4=tk.Button(root, text="orange", command=fun52,width=8) b4.pack() b4.place(x=300 ,y=310) b5=tk.Button(root, text="yellow", command=fun62,width=8) b5.pack() b5.place(x=300 ,y=340) b6=tk.Button(root, text="green", command=fun72,width=8) b6.pack() b6.place(x=300 ,y=370) b7=tk.Button(root, text="blue", command=fun82,width=8) b7.pack() b7.place(x=300 ,y=400) b8=tk.Button(root, text="purple", command=fun92,width=8) b8.pack() b8.place(x=300 ,y=430) b9=tk.Button(root, text="gold", command=fun102,width=8) b9.pack() b9.place(x=300 ,y=460) b10=tk.Button(root, text="silver", command=fun112,width=8) b10.pack() b10.place(x=300 ,y=490) t1 = w.create_text(450, 200, text="fourth color: ",font="Courier 10 bold ", fill ="black",anchor='w') b2=tk.Button(root, text="brown", command=fun23,width=8) b2.pack() b2.place(x=450 ,y=220) b3=tk.Button(root, text="red ", command=fun33,width=8) b3.pack() b3.place(x=450 ,y=250) b11=tk.Button(root, text="gold", command=fun43,width=8) b11.pack() b11.place(x=450 ,y=280) b12=tk.Button(root, text="silver", command=fun53,width=8) b12.pack() b12.place(x=450 ,y=310) t2=w.create_text(500, 20, text=" 44 ") t3=w.create_text(500, 50, text=" 55 ") t4=w.create_text(500, 80, text=" 66 ") t5=w.create_text(500, 110, text=" 77 ") t6=w.create_text(500, 140, text=" 88 ") def funf(): z=(x+x1)*x2 w.itemconfig(t6,text=z) bfin=tk.Button(root, text="CALCULATE", command=funf,font="24") bfin.pack() bfin.place(x=400 ,y=500) w.mainloop() *The main problem is that I can`t read variables x, x1, x2 on button "CALCULATE" press. Thank you for support!* -- View this message in context: http://python.6.n6.nabble.com/Tkinter-variable-sharing-from-function-to-function-tp4544506p4544506.html Sent from the Python - tkinter-discuss mailing list archive at Nabble.com. _______________________________________________ Tkinter-discuss mailing list Tkinter-discuss@python.org http://mail.python.org/mailman/listinfo/tkinter-discuss