RISOLTO [Python] GUI lancia funzione all'apertura e non dopo click su bottone

dgcross

Utente Attivo
1,279
342
CPU
Ryzen 5 5600X
Dissipatore
EK Supremacy EVO (2x Alphacool NexXxoS ST30 360mm)
Scheda Madre
ASRock X370 Gaming K4
HDD
Samsung 980 Pro 512GB, Samsung 870 EVO 2TB, Goodram CX300 480GB, Toshiba P300 3TB
RAM
2x8+2x16 G.Skill TridentZ RGB @3400MHz CL16
GPU
Galax 2080 Ti HOF OC Lab + liquido custom (2x Alphacool NexXxoS ST30 360mm)
Audio
Alientek D8, Fiio Q1 Mark II, Mission LX-1, Sennheiser HD598 SE
Monitor
Samsung U28E590D
PSU
Corsair AX860i
Case
Lian Li O11 Dynamic
Periferiche
Ozone Strike Pro Spectra, Steelseries Rival 500, DualSense
Net
Tiscali
OS
Windows 10 Pro
Ciao a tutti,
mi sto lanciando nella creazione di piccole GUI per i programmi che finora ho lanciato da riga di comando, ma non sta andando molto bene.
Guardando in giro ho deciso di cominciare con PAGE e ho creato una prima GUI di prova che dovrebbe solamente lanciare uno script alla pressione di un bottone, solo che lancia lo script in apertura e poi premendo il bottone non fa nulla
Qualcuno saprebbe dirmi dov'è l'errore (di seguito allego il codice)? Grazie

Python:
#! /usr/bin/env python
#  -*- coding: utf-8 -*-
#
# GUI module generated by PAGE version 4.23
#  in conjunction with Tcl version 8.6
#    May 26, 2019 12:16:24 PM CEST  platform: Windows NT

import sys

try:
    import Tkinter as tk
except ImportError:
    import tkinter as tk

try:
    import ttk
    py3 = False
except ImportError:
    import tkinter.ttk as ttk
    py3 = True

import prova_GUI_support

def vp_start_gui():
    '''Starting point when module is the main routine.'''
    global val, w, root
    root = tk.Tk()
    top = Toplevel1 (root)
    prova_GUI_support.init(root, top)
    root.mainloop()

w = None
def create_Toplevel1(root, *args, **kwargs):
    '''Starting point when module is imported by another program.'''
    global w, w_win, rt
    rt = root
    w = tk.Toplevel (root)
    top = Toplevel1 (w)
    prova_GUI_support.init(w, top, *args, **kwargs)
    return (w, top)

def destroy_Toplevel1():
    global w
    w.destroy()
    w = None

class Toplevel1:
    def __init__(self, top=None):
        '''This class configures and populates the toplevel window.
           top is the toplevel containing window.'''
        _bgcolor = '#d9d9d9'  # X11 color: 'gray85'
        _fgcolor = '#000000'  # X11 color: 'black'
        _compcolor = '#d9d9d9' # X11 color: 'gray85'
        _ana1color = '#d9d9d9' # X11 color: 'gray85'
        _ana2color = '#ececec' # Closest X11 color: 'gray92'

        top.geometry("600x457+2386+481")
        top.title("New Toplevel")
        top.configure(background="#d9d9d9")
        top.configure(highlightbackground="#d9d9d9")
        top.configure(highlightcolor="black")

        self.Entry1 = tk.Entry(top)
        self.Entry1.place(relx=0.333, rely=0.153,height=20, relwidth=0.273)
        self.Entry1.configure(background="white")
        self.Entry1.configure(disabledforeground="#a3a3a3")
        self.Entry1.configure(font="TkFixedFont")
        self.Entry1.configure(foreground="#000000")
        self.Entry1.configure(highlightbackground="#d9d9d9")
        self.Entry1.configure(highlightcolor="black")
        self.Entry1.configure(insertbackground="black")
        self.Entry1.configure(selectbackground="#c4c4c4")
        self.Entry1.configure(selectforeground="black")

        self.Button1 = tk.Button(top)
        self.Button1.place(relx=0.7, rely=0.153, height=24, width=47)
        self.Button1.configure(activebackground="#ececec")
        self.Button1.configure(activeforeground="#000000")
        self.Button1.configure(background="#d9d9d9")
        self.Button1.configure(command=prova_GUI_support.esegui_pca())
        self.Button1.configure(disabledforeground="#a3a3a3")
        self.Button1.configure(foreground="#000000")
        self.Button1.configure(highlightbackground="#d9d9d9")
        self.Button1.configure(highlightcolor="black")
        self.Button1.configure(pady="0")
        self.Button1.configure(text='''PCA''')

        self.Entry2 = tk.Entry(top)
        self.Entry2.place(relx=0.333, rely=0.241,height=20, relwidth=0.273)
        self.Entry2.configure(background="white")
        self.Entry2.configure(disabledforeground="#a3a3a3")
        self.Entry2.configure(font="TkFixedFont")
        self.Entry2.configure(foreground="#000000")
        self.Entry2.configure(highlightbackground="#d9d9d9")
        self.Entry2.configure(highlightcolor="black")
        self.Entry2.configure(insertbackground="black")
        self.Entry2.configure(selectbackground="#c4c4c4")
        self.Entry2.configure(selectforeground="black")

        self.Entry3 = tk.Entry(top)
        self.Entry3.place(relx=0.333, rely=0.306,height=20, relwidth=0.273)
        self.Entry3.configure(background="white")
        self.Entry3.configure(disabledforeground="#a3a3a3")
        self.Entry3.configure(font="TkFixedFont")
        self.Entry3.configure(foreground="#000000")
        self.Entry3.configure(highlightbackground="#d9d9d9")
        self.Entry3.configure(highlightcolor="black")
        self.Entry3.configure(insertbackground="black")
        self.Entry3.configure(selectbackground="#c4c4c4")
        self.Entry3.configure(selectforeground="black")

        self.Label1 = tk.Label(top)
        self.Label1.place(relx=0.15, rely=0.153, height=21, width=97)
        self.Label1.configure(activebackground="#f9f9f9")
        self.Label1.configure(activeforeground="black")
        self.Label1.configure(background="#d9d9d9")
        self.Label1.configure(disabledforeground="#a3a3a3")
        self.Label1.configure(foreground="#000000")
        self.Label1.configure(highlightbackground="#d9d9d9")
        self.Label1.configure(highlightcolor="black")
        self.Label1.configure(text='''Cartella Database''')

        self.Label2 = tk.Label(top)
        self.Label2.place(relx=0.233, rely=0.241, height=21, width=50)
        self.Label2.configure(activebackground="#f9f9f9")
        self.Label2.configure(activeforeground="black")
        self.Label2.configure(background="#d9d9d9")
        self.Label2.configure(disabledforeground="#a3a3a3")
        self.Label2.configure(foreground="#000000")
        self.Label2.configure(highlightbackground="#d9d9d9")
        self.Label2.configure(highlightcolor="black")
        self.Label2.configure(text='''Mescola''')

        self.Label3 = tk.Label(top)
        self.Label3.place(relx=0.217, rely=0.306, height=21, width=61)
        self.Label3.configure(activebackground="#f9f9f9")
        self.Label3.configure(activeforeground="black")
        self.Label3.configure(background="#d9d9d9")
        self.Label3.configure(disabledforeground="#a3a3a3")
        self.Label3.configure(foreground="#000000")
        self.Label3.configure(highlightbackground="#d9d9d9")
        self.Label3.configure(highlightcolor="black")
        self.Label3.configure(text='''Data Inizio''')

        self.Label4 = tk.Label(top)
        self.Label4.place(relx=0.217, rely=0.372, height=21, width=55)
        self.Label4.configure(activebackground="#f9f9f9")
        self.Label4.configure(activeforeground="black")
        self.Label4.configure(background="#d9d9d9")
        self.Label4.configure(disabledforeground="#a3a3a3")
        self.Label4.configure(foreground="#000000")
        self.Label4.configure(highlightbackground="#d9d9d9")
        self.Label4.configure(highlightcolor="black")
        self.Label4.configure(text='''Data Fine''')

        self.Entry4 = tk.Entry(top)
        self.Entry4.place(relx=0.333, rely=0.372,height=20, relwidth=0.273)
        self.Entry4.configure(background="white")
        self.Entry4.configure(disabledforeground="#a3a3a3")
        self.Entry4.configure(font="TkFixedFont")
        self.Entry4.configure(foreground="#000000")
        self.Entry4.configure(highlightbackground="#d9d9d9")
        self.Entry4.configure(highlightcolor="black")
        self.Entry4.configure(insertbackground="black")
        self.Entry4.configure(selectbackground="#c4c4c4")
        self.Entry4.configure(selectforeground="black")

        self.Button2 = tk.Button(top)
        self.Button2.place(relx=0.683, rely=0.219, height=24, width=60)
        self.Button2.configure(activebackground="#ececec")
        self.Button2.configure(activeforeground="#000000")
        self.Button2.configure(background="#d9d9d9")
        self.Button2.configure(disabledforeground="#a3a3a3")
        self.Button2.configure(foreground="#000000")
        self.Button2.configure(highlightbackground="#d9d9d9")
        self.Button2.configure(highlightcolor="black")
        self.Button2.configure(pady="0")
        self.Button2.configure(text='''Centroidi''')

if __name__ == '__main__':
    vp_start_gui()
Python:
#! /usr/bin/env python
#  -*- coding: utf-8 -*-
#
# Support module generated by PAGE version 4.23
#  in conjunction with Tcl version 8.6
#    May 26, 2019 12:16:03 PM CEST  platform: Windows NT

import sys
import pca

try:
    import Tkinter as tk
except ImportError:
    import tkinter as tk

try:
    import ttk
    py3 = False
except ImportError:
    import tkinter.ttk as ttk
    py3 = True

def esegui_pca():
    print('prova_GUI_support.pca')
    # pca.analizza()
    # sys.stdout.flush()

def init(top, gui, *args, **kwargs):
    global w, top_level, root
    w = gui
    top_level = top
    root = top

def destroy_window():
    # Function which closes the window.
    global top_level
    top_level.destroy()
    top_level = None

if __name__ == '__main__':
    import prova_GUI
    prova_GUI.vp_start_gui()
Post unito automaticamente:

ok, ho risolto: nel primo file dove ho scritto self.Button1.configure(command=prova_GUI_support.esegui_pca()) dovevo omettere le parentesi.
Qualcuno sa spiegarmi il perché però? Grazie
 
Ultima modifica:

Mursey

Super Moderatore
Staff Forum
Utente Èlite
8,229
5,658
Non conosco Python ma suppongo che la presenza delle parentesi veniva interpretata come esecuzione in fase di configurazione e non a ogni pressione.
 

Entra

oppure Accedi utilizzando
Discord Ufficiale Entra ora!