Il pretesto è quello di creare un programmino per scorporare l’iva dal totale della fattura. Useremo Python
e PyQt6
per creare un’interfaccia grafica al semplice programma. Qui, il repository da cui prelevare i sorgenti.

imponibile.ui
Al pulsante pB_calcola
colleghiamo il signal pB_valutaClick()
quando si verifica l’evento clicked()
.

Di seguito il codice:
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 | #!/usr/bin/python from PyQt6.QtWidgets import QApplication, QWidget from PyQt6 import uic class Ui(QWidget): def __init__( self ): super ().__init__() uic.loadUi( 'imponibile.ui' , self ) self .setFixedSize( 399 , 177 ) def pB_valutaClick( self ): try : n1 = float ( self .lE_totFattura.text()) n2 = float ( self .lE_aliquota.text()) n3 = n1 * 100 / (n2 + 100 ) n4 = n1 - n3 self .lE_imponibile.setText( str ( format (n3, '>12.2f' ))) self .lE_iva.setText( str ( format (n4, '>12.2f' ))) self .l_errore.setText('') except : self .l_errore.setText( 'Valore numerico non accettato' ) self .lE_imponibile.setText('') self .lE_iva.setText('') self .lE_aliquota.setText( '22' ) app = QApplication([]) window = Ui() window.show() app. exec () |
Lo screencast seguente mostra il funzionamento del programma: