Feb-12-2020, 11:37 AM
Dear Sirs,
This is my python code:
I don't know why change button and checkbutton state is impossible for me.
I tried to use:
b1.state('normal')
b2['state'] = 'normal'
b0.config(state = 'disabled')
b0.config(state=NORMAL)
no one works!
Why?
Thanks for Your help
Best Regards
This is my python code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
from tkinter import * import math import numpy as np gui = Tk() gui.title( "Money Split" ) gui.geometry( "580x200" ) v1 = IntVar() v2 = IntVar() v3 = IntVar() v4 = IntVar() def testVal(inStr,i,acttyp): ind = int (i) if acttyp = = '1' : #insert if not inStr[ind].isdigit(): return False return True R = 4 C = 3 valore = StringVar() # Initialize np np = [[ 50 , 0 , 0 ], [ 20 , 0 , 0 ], [ 10 , 0 , 0 ], [ 5 , 0 , 0 ]] # For printing the np def shownp(): for i in range (R): for j in range (C): print (np[i][j], end = " " ) print () #create a callback for our button def callback(): global b50 global a1 if e0.get() ! = '': importo = int (e0.get()) status_label[ 'text' ] = importo if importo % 5 = = 0 and importo > = 5 : if v1.get(): b50 = int (e1.get()) else : if importo > = 50 : b50 = math.ceil(importo / 85 ) else : b50 = 0 np [ 0 ][ 2 ] = b50 a1 = str (b50) e1.delete( 0 , END) e1.insert( 0 , a1) if v2.get(): b20 = int (e2.get()) else : if (importo - b50 * 50 ) > = 20 : b20 = math.ceil((importo - b50 * 50 ) / 35 ) else : b20 = 0 np [ 1 ][ 2 ] = b20 a2 = str (b20) e2.delete( 0 , END) e2.insert( 0 , a2) if v3.get(): b10 = int (e3.get()) else : if (importo - b50 * 50 - b20 * 20 ) > = 10 : b10 = math.ceil((importo - b50 * 50 - b20 * 20 ) / 15 ) else : b10 = 0 np [ 2 ][ 2 ] = b10 a3 = str (b10) e3.delete( 0 , END) e3.insert( 0 , a3) if v4.get(): b5 = int (e4.get()) else : if (importo - b50 * 50 - b20 * 20 - b10 * 10 ) > = 5 : b5 = math.ceil((importo - b50 * 50 - b20 * 20 - b10 * 10 ) / 5 ) else : b5 = 0 np [ 3 ][ 2 ] = b5 a4 = str (b5) e4.delete( 0 , END) e4.insert( 0 , a4) print (b50 * 50 + b20 * 20 + b10 * 10 + b5 * 5 ) shownp() status_label[ 'text' ] = 'Done!' b1.state( 'normal' ) b2[ 'state' ] = 'normal' b3[ 'state' ] = 'normal' b4[ 'state' ] = 'normal' else : status_label[ 'text' ] = 'Insert a number divisible by 5' e0.delete( 0 ,END) e1.delete( 0 ,END) e2.delete( 0 ,END) e3.delete( 0 ,END) e4.delete( 0 ,END) b1.configure(state = 'disabled' ) b2.configure(state = 'disabled' ) b3.configure(state = 'disabled' ) b4.configure(state = 'disabled' ) e0.focus def change50(v1): print (v1) e1.delete( 0 ,END) e2.delete( 0 ,END) e3.delete( 0 ,END) e4.delete( 0 ,END) e1.insert( 0 , np [ 0 ][ 2 ] + v1) np [ 0 ][ 1 ] = 1 callback() def change20(v2): e1.delete( 0 ,END) e2.delete( 0 ,END) e3.delete( 0 ,END) e4.delete( 0 ,END) e2.insert( 0 , np [ 1 ][ 2 ] + v2) np [ 1 ][ 1 ] = 1 callback() def change10(v3): e1.delete( 0 ,END) e2.delete( 0 ,END) e3.delete( 0 ,END) e4.delete( 0 ,END) e3.insert( 0 , np [ 2 ][ 2 ] + v3) np [ 2 ][ 1 ] = 1 callback() def change5(v4): e1.delete( 0 ,END) e2.delete( 0 ,END) e3.delete( 0 ,END) e4.delete( 0 ,END) e3.insert( 0 , np [ 3 ][ 2 ] + v4) np [ 3 ][ 1 ] = 1 callback() def verifica(event = None ): val1 = v1.get() * int (e1.get()) * 50 val2 = v2.get() * int (e2.get()) * 20 val3 = v3.get() * int (e3.get()) * 10 val4 = v4.get() * int (e4.get()) * 5 print (val1,val2,val3,val4) somma = val1 + val2 + val3 + val4 print (somma) valtot = int (e0.get()) if somma > valtot: b0.config(state = 'disabled' ) status_label[ 'text' ] = 'Change the fixed number of banknotes because it exceeds the amount to be split!' else : b0.config(state = NORMAL) Label(gui, text = "Importo" ).place(x = 5 , y = 5 , width = 50 ) Label(gui, text = "50,00 €" ).place(x = 5 , y = 35 , width = 50 ) Label(gui, text = "20,00 €" ).place(x = 5 , y = 65 , width = 50 ) Label(gui, text = "10,00 €" ).place(x = 5 , y = 95 , width = 50 ) Label(gui, text = "5,00 €" ).place(x = 5 , y = 125 , width = 50 ) a1 = StringVar() a2 = StringVar() a3 = StringVar() a4 = StringVar() e0 = Entry(gui, validate = "key" , justify = 'center' ) e0[ 'validatecommand' ] = (e0.register(testVal), '%P' , '%i' , '%d' ) e1 = Entry(gui, textvariable = a1, justify = 'center' ) e2 = Entry(gui, textvariable = a2, justify = 'center' ) e3 = Entry(gui, textvariable = a3, justify = 'center' ) e4 = Entry(gui, textvariable = a4, justify = 'center' ) #e0.grid(row=0, column=1) e0.place(x = 100 , y = 5 , width = 100 ) e1.place(x = 100 , y = 35 , width = 100 ) e2.place(x = 100 , y = 65 , width = 100 ) e3.place(x = 100 , y = 95 , width = 100 ) e4.place(x = 100 , y = 125 , width = 100 ) b0 = Button(gui, text = "Split" , state = 'normal' , command = callback).place(x = 100 , y = 155 , height = 20 , width = 100 ) b1 = Checkbutton(gui, text = "fix" , state = 'disabled' , variable = v1, command = verifica).place(x = 210 , y = 35 , height = 20 , width = 100 ) b2 = Checkbutton(gui, text = "fix" , state = 'disabled' ,variable = v2, command = verifica).place(x = 210 , y = 65 , height = 20 , width = 100 ) b3 = Checkbutton(gui, text = "fix" , state = 'disabled' ,variable = v3, command = verifica).place(x = 210 , y = 95 , height = 20 , width = 100 ) b4 = Checkbutton(gui, text = "fix" , state = 'disabled' ,variable = v4, command = verifica).place(x = 210 , y = 125 , height = 20 , width = 100 ) b5 = Button(gui, text = "Quit" , command = gui.destroy).place(x = 370 , y = 155 , height = 20 , width = 100 ) status_label = Label(gui, height = 3 , width = 35 , bg = "black" , fg = "#00FF00" , text = "---" , wraplength = 200 ) status_label.place(x = 300 , y = 35 , width = 250 ) e0.focus() gui.mainloop() |
I tried to use:
b1.state('normal')
b2['state'] = 'normal'
b0.config(state = 'disabled')
b0.config(state=NORMAL)
no one works!

Why?

Thanks for Your help
Best Regards