Я действительно знаю, почему ми кнопка остается нажатой, вопрос больше похож на: Как я могу избежать этого? Исходный код ниже, спасибо:
import tkinter as tk
from tkinter import filedialog as fd
# creacion de cada venta
# ---ventana 1---
class Window1(tk.Frame):
final_path = ""
def __init__(self, parent):
# inicio y creacion del propio frame
tk.Frame.__init__(self, parent)
self.config(bg="#33ccff", width='990', height='250')
# primera etiqueta con valores
self.label1 = tk.Label(
self, text="Documento Seleccionado", bg="#33ccff")
# segunda etiqueta con texto variable
self.txt_carga = tk.StringVar()
self.txt_carga.set("Archivo no seleccionado")
self.label2 = tk.Label(self, textvariab=self.txt_carga, bg="#33ccff")
# primer boton de carga de documentos y funcion del boton
self.load_button = tk.Button(self, text="Cargar Documento")
# segundo boton de siguiente
self.next_button = tk.Button(self, text="Siguiente")
# Definicion de funciones (Con binding hay que añadir el evento al boton)
def function_load(event):
path = fd.askopenfile(filetype=(("Excel", ".xlsx"), ("CSV", ".csv"), ("Todos los Archivos", "*.*")))
self.final_path = str(path.name)
self.txt_carga.set(path.name)
def function_next(event):
print(self.final_path)
# binding: de esta manera se llama a las funciones de los botones al final de forma
# que queda mas ordenado, (x,y) -> x = tipo de evento, y = funcion donde se define
self.load_button.bind('<ButtonPress-1>', function_load)
self.next_button.bind('<Button-1>', function_next)
# instanciacion de los objetos en la ventana
self.label1.grid(row=0, column=0, columnspan=2, padx=200, pady=25)
self.label2.grid(row=1, column=0, columnspan=2, pady=25)
self.load_button.grid(row=2, column=0, pady=20)
self.next_button.grid(row=2, column=1, pady=20)
# ---ventana inicio------
class MainWindow(tk.Frame):
def __init__(self, parent, *args, **kwargs):
self.parent = parent
# necesario para que este se inicie como objeto de la clase Frame
tk.Frame.__init__(self, parent, *args, **kwargs)
# INSANCIAS
self.window1 = Window1(self) # instancia de la clase
self.window1.pack() # empaquetado de la clase
self.pack() # empaquetado propio
# creo el main del programa
if __name__ == "__main__":
root = tk.Tk()
MainWindow(root)
root.mainloop()
Как вы можете видеть, в моей программе есть окно, в которое я вставил пару ярлыков и пару кнопок. Проблема вызвана функцией, присвоенной load_button (def function_load), потому что файл filelog открывается, но я полагаю, что процесс продолжает работать, и это вызывает нажатие кнопки.