0

I'm new to the code and I'm experiencing with tkinter, and I'm making a money counter with tkinter and to make it happen on screen i need to make a Label change it's text properties form one text to another one with a button, the problem is that it works on console, but when I try to make it change on tkinter it freezes and doesn't change. The parts I'm talking about are, the ones highlighted with (----code----).

I know that the problem concerns threading, due to the fact that the programs runs when I remove the keyboard.is_pressed, but i don't actually know how to implement it.

from tkinter import *

import keyboard

import sys

import time

import winsound

raiz = Tk()

raiz.title("Contador de Divisas")

raiz.iconbitmap("MonedaContador.ico")


Total = 0

def contador_de_espacios(divisa, diccionario):
    global lista
    global Total
    global posiciones_en_diccionario
    Numero = ""
    Contador = 0
    Escape = 0
    Cambiar = 0
    Multiplicador = divisa * 5
    Nombre = str(divisa)
    suma_lista = 0

    if divisa > 2:
        Nombre = (" billetes de " + Nombre + " Euros.")
    else:
        Nombre = (" Monedas de " + Nombre + " Euro/s.")
    eleccion.config(text = Nombre)----------------------------
    while True:

            if keyboard.is_pressed('space'):
                Control = 0
                Contador += 1
                Numero = str(Contador)
                Marcador.config(text = Numero)-------------------------------
                winsound.Beep(2500, 200)
                time.sleep(0.25)



def clasificador_de_divisa(boton):

    global posiciones_en_lista

    posicion = posiciones_en_lista.get(str(boton))

    contador_de_espacios(boton, posicion)

myframe = Frame()

myframe.pack()

myframe.config(width = "650", height = "350")

explicacion = Label(myframe, text = "Esto es un contador de divisas en euros. Por cada grupo de 5 monedas/billetes le das una vez al espacio, cosa que añadirá 1 monton de 5 monedas/billetes al contador.")

explicacion.grid(row = 0, column = 0, padx = 10, pady = 30, columnspan = 9)

explicacion.config(font = (30))

eleccion = Label(myframe)--------------------------------------

eleccion.grid(row = 1, column = 2, padx = 10, pady = 30, columnspan = 5)

eleccion.config(font = (30))

Marcador = Label(myframe, text = "0")

Marcador.grid(row = 2, column = 3, pady = 30, columnspan = 3, rowspan = 1)

Marcador.config(font=("Arial",100), bg = "black", fg = "white")

boton1euro = Button(myframe, text = "1 Euro", width = 10, command = lambda:clasificador_de_divisa(1))
boton1euro.grid(row = 3, column = 0, padx = 10, pady = 30)

raiz.mainloop()

The expected output is the program changing the Label, but it doesn't and freezes.

  • 1
    That seems like an awful lot of code. Please try to reduce it dow to a [mcve]. – Bryan Oakley Aug 20 '19 at 02:04
  • I've done that but i don't know how to change the code i've already put here, what i've realized is that when I eliminate the keyboard.is_pressed it works fine, so maybe it has something to do with that. – Psycho_jalvaro Aug 20 '19 at 02:18
  • Read [Freezing during the execution of a function](https://stackoverflow.com/questions/10847626/program-freezing-during-the-execution-of-a-function-in-tkinter) – stovfl Aug 20 '19 at 08:24

0 Answers0