Interface graphique GUI

Programmeurnul Messages postés 15 Date d'inscription   Statut Membre Dernière intervention   -  
Phil_1857 Messages postés 1872 Date d'inscription   Statut Membre Dernière intervention   -
Bonjour,

quel interface graphique choisir par manque de temps qui n'est pas trop difficile à coder (tkinter ? pyqt5 ? ... ? )

merci
A voir également:

18 réponses

Phil_1857 Messages postés 1872 Date d'inscription   Statut Membre Dernière intervention   168
 
Bonjour Programmeurnul,

On peut déjà commencer avec tkinter, d'autant que ce module est normalement déjà inclus dans l'install de Python, donc utilisable immédiatement
0
Phil_1857 Messages postés 1872 Date d'inscription   Statut Membre Dernière intervention   168
 
Holà Programmeurnul,

J'ai vu ta réponse dans un mail, mais je ne la vois pas apparaitre ici: bug ? fausse manip ???

En tout cas peux-tu me montrer ici le code que tu as essayé, en utilisant les balises pour la clarté et les indentations, voici le mode d'emploi:

https://codes-sources.commentcamarche.net/faq/11288-les-balises-de-code
0
Programmeurnul Messages postés 15 Date d'inscription   Statut Membre Dernière intervention  
 
C'est parce que je te l'ai envoyé en privé, alors je mets cela ici :

import random
import csv
import os
import requests
import matplotlib.pyplot as plt
from crypto import BTC, ETH, XRP, USDT, BCH, BSV, LTC, BNB,EOS, XTZ

# Global functions 
def Intro (): 
    
    print(           '\n\t##Welcome to Ewallet Services## \
                      \n\nWhich action would you like to take? \
                      \n\n 1 : Create a new profile \
                      \n 2 : Access to an existing account \
                      \n 3 : Quit Ewallet Services')

def currency_info ():
    print('')
    
fees = 0.005
Fees = fees * 100
Fees_perc = '{} %'.format(Fees) 


class Ewallet :
  

    def __init__(self,Id,Pwd,InAmount,accounts,crypto,Iban):
        self.Id = Id
        self.Pwd = Pwd
        self.InAmount = InAmount
        self.accounts = {'CHF' : InAmount, 'EUR' : 0, 'USD' : 0,'GBP' : 0,\
                         'JPY' : 0,'AUD' : 0,'NZD' : 0,'CAD' : 0,\
                        'NOK' : 0,'SEK' :0}
        self.crypto = {'BTC' : 0,'ETH' : 0,'XRP' : 0,'USDT' : 0,\
                      'BCH' : 0,'BSV' : 0,'LTC' : 0,'BNB' : 0,\
                          'EOS' : 0,'XTZ' : 0}
        self.Iban = Iban
    
    def Information (self): 
        info = '\nAccount ID : {}\nPin code : {}\nIban : {} \nFees on trx : {}\
            \n\nAccount bal. {}\
            \nCryptocurry bal. {} \n'\
            .format(self.Id,self.Pwd,self.Iban,\
                    Fees_perc,self.accounts,self.crypto)
        print(info)
    

    def CreditOp(self,amount):
            self.InAmount += amount
            return self.InAmount
    
    def DebitOperation(self,amount):
        if self.InAmount > amount :
            self.InAmount -= amount 
            return self.InAmount
        else : 
            print("Insufficient funds!")
        
            
    def codeVerification(self,code): 
        if (self.Pwd == code): 
            return True 
        else : 
            return False 

    def save(self):
        self.accounts = str(self.accounts)
        self.crypto = str(self.crypto)
        instring = self.accounts.replace(",", "_")
        instring_2 = self.crypto.replace(",", "_")
        info ='{:},{:},{:},{:},{:},{:}'\
            .format(self.Id,self.Pwd,\
                    self.InAmount,instring,instring_2,self.Iban)
        return info

                                        
    def covertisseur_currencies (self,from_currency, to_currency, amount): 
        rates = {}
        url = "https://api.exchangeratesapi.io/latest"
        data = requests.get(url).json()
        rates = data["rates"]
        if to_currency == "EUR" and from_currency != "EUR" : 
            amount = round(amount / rates[from_currency], 4)
            return amount
        elif from_currency == "EUR" and to_currency == "EUR":
            amount = round(amount, 4)
            return amount
        elif from_currency == 'EUR' and to_currency != 'EUR':
            amount = round(amount *rates[to_currency],4)
            return amount
        
        else:
            amount = \
                round(amount * rates[to_currency] / rates[from_currency], 4)
            return amount
            
        
class Bank : 
    
    def __init__(self):
        if os.path.exists(r"Ewallet.csv"):
            self.Liste_Ewallet = []
            with open('Ewallet.csv', 'r') as file:
                reader = csv.reader(file)
                wallet_list = []
                for row in reader:
                    wallet_list.append(row)
            for i in range(len(wallet_list)): 
                newListe = []
                newListe = wallet_list[i]
                newListe[0], newListe[1] , newListe [2] , newListe [3] = str(newListe[0]),\
                    int(newListe[1]) , float(newListe[2]) , str(newListe[3])
                a = newListe[3].replace("_", ",")
                b = newListe[4].replace("_", ",")
                eval(a)
                
                wallet_1 = Ewallet(newListe[0],newListe[1],newListe[2], a, b,\
                                   newListe[3])
                self.Liste_Ewallet.append(wallet_1)
        else:
            self.Liste_Ewallet = []
  
    def saveBank(self): 
        pw = open('Ewallet.csv','w')
        for index , elem in enumerate(self.Liste_Ewallet) :
            pw.write('{}\n'.format(self.Liste_Ewallet[index].save()))
        pw.close()
    
    def existAcc (self,Id_entered): 
        for index, elem in enumerate(self.Liste_Ewallet) : 
            if  self.Liste_Ewallet[index].Id == Id_entered:
                return (True,index) 
        return (False,0)  
    
    # ajouter les caractère à bloquer 
    def blockEntry (self,client_id): 
        char = ['é','è','à','ê','ç',
    ',','.',';',':','-','?','!','/','"',
    '%','(',')','=','+','*','@','¦','|'] 
        list_count = []
        exist = False
        for spec in char :
            count_char = 0
            count_char = client_id.count(spec) 
            list_count.append(count_char)
        for index , elem in enumerate(list_count):
            if list_count[index] > 0 : 
                exist = True 
                return exist
            else : 
                pass
        return exist
        
    def newWallet (self) :
        client_id = input('Enter an ID to open an account \n>')
        if self.blockEntry(client_id) == False :
            cond, index = self.existAcc(client_id); 
            if cond == False:
                client_id_clean = client_id.replace(" ","")
                
                print('ID accepted!\n')
                ok = False 
                initial_amount = 0; 
                while ok == False and initial_amount <= 0 :
                    try :
                        initial_amount = float(input('Enter amount \n>'))
                        if initial_amount <= 0 : 
                            print('\nThe amount entered \
                                      must be positive !\n')
                        else :
                            print('Amount accepted!\n')
                            ok = True 
                    except : 
                        print('\nThe amount entered must be positive!\n')
                    
                numerical_code = random.randrange(100000,1000000)
                #Iban suisse / suisse : CH / 21 char
                numbers = str(random.randrange(1000000000000000000,10000000000000000000))
                Iban = 'CH' + numbers
                wallet = Ewallet(client_id_clean,numerical_code,\
                                 initial_amount,0,0,Iban)
                self.Liste_Ewallet.append(wallet)
                print('Account information:\n')
                wallet.Information()  
            else: 
                print('\nThis ID is already taken!\n')      
        else : 
            print('\nYour ID cannot contain special characters!')  
            
            
    def modif_Id(self):
        stop = False 
        while stop == False: 
            new_Id = input('Enter your new ID >')
            cond, ind = self.existAcc(new_Id)
            char_notAllow = self.blockEntry(new_Id)
            if cond == True:
                print('\nThis ID is already taken!')
            elif char_notAllow == True : 
                print('Your ID cannot contain special characters!')
                
            if cond == False and char_notAllow == False : 
                return new_Id
            
    def modif_code(self):
        stop = False 
        while stop == False :
            print('Your password must contain 6 numbers')
            new_code = input('Enter your new password >')
            if len(new_code) == 6:
                new_code = int(new_code) 
                stop == True 
                return new_code

        
    def verif_sold(self,clef,Index):
        sold_neg = False 
        if self.Liste_Ewallet[Index].accounts[clef] == 0:
            sold_neg = True 
            return sold_neg
        return sold_neg
        
    def graph_curr(self,Index):
        curr_arr = ['CHF','EUR','USD','GBP','JPY',\
                    'AUD','NZD','CAD','NOK','SEK']
        amount_curr = []
        total_money = 0
        for curr in curr_arr: 
            amount_curr.append(self.Liste_Ewallet[Index].accounts[curr])
            total_money += self.Liste_Ewallet[Index].accounts[curr]
        sizes = []
        for curr in amount_curr:
            sizes.append((curr / total_money)*100)
        labels = 'CHF', 'EUR','USD','GBP','JPY','AUD','NZD','CAD','NOK','SEK'
        explode = (0, 0, 0, 0,0,0,0,0,0,0)  # only "explode" the 2nd slice 
        fig1, ax1 = plt.subplots()
        plt.title('Currencies',fontsize = 20)
        ax1.pie(sizes, explode=explode, labels=labels, autopct='%1.1f%%',
        shadow=True, startangle=90)
        ax1.axis('equal')  
        plt.show()
    
    def curr_units (self,clef,amount):
        crypto_list = ['BTC','ETH','XRP','USDT','BCH',\
                      'BSV','LTC','BNB','EOS','XTZ']
        crypto_price = [BTC, ETH, XRP, USDT, BCH, BSV, LTC, BNB,EOS, XTZ]
        crypto_units = 0
        for index, curr in enumerate(crypto_list) : 
            if curr == clef : 
                crypto_units +=  amount / crypto_price[index]  
                return crypto_units
            
    def verif_unitCurr (self,clef,Index):
        no_units = False 
        if self.Liste_Ewallet[Index].crypto[clef] == 0 : 
            no_units = True 
            return no_units
        else : 
            return no_units 
    
    def amount_sell_crypto(self, clef, units_sell) : 
        crypto_list = ['BTC','ETH','XRP','USDT','BCH','BSV','LTC','BNB','EOS','XTZ']
        crypto_price = [BTC, ETH, XRP, USDT, BCH, BSV, LTC, BNB,EOS, XTZ]
        amount_sell_crypto = 0
        for index,curr in enumerate(crypto_list) :
            if curr == clef : 
                amount_sell_crypto = units_sell * crypto_price[index] 
                return round(amount_sell_crypto,4)
    
    
    def choice_func(self,inp):
        b = 'Buy'
        s = 'Sell'
        if inp == '1' :
            return b
        elif inp == '2' :
            return s
        
    def verif_iban (self,Iban):
        correct_Iban = False
        list_Iban = ['AE','CH','DE','ES','GB','IL','IT']
        list_numb = [23,21,22,24,22,23,27]
        code = Iban[:2]
        for index,elem in enumerate(list_Iban):
            if elem == code : 
                if len(Iban) == list_numb[index]: 
                    correct_Iban = True 
                    return (correct_Iban,list_numb[index])
                else :
                    return (correct_Iban,list_numb[index])
    
    def accountOp(self): 
        client_id_op = input('Enter the account ID \n>')
        cond, index = self.existAcc(client_id_op); 
        if cond == True : 
            print('\nAccount found!\n')
            ok = False 
            pin_entered = 0
            try :
                while ok == False:
                    pin_entered = int(input('Enter the account password \n>'))
                    ok = True 
            except:
                pass
            if self.Liste_Ewallet[index].codeVerification(pin_entered):
                print('\nCorrect pin ')
                print('Connexion succeeded \n')
                stop_accountOp = False
                while stop_accountOp == False :
                    print('\nWhich action would you like to take ? \
                          \n 1 : Withdrawal \n 2 : Deposit \n 3 : Information \
                              \n 4 : Converter \n 5 : Modify or delete account\
                                  \n 6 : Cryptocurrency \n 7 : QUIT ')
                    op = 0; 
                    try : 
                        op = int(input('>'))
                    except : 
                        pass
                    
                    if op == 1 :
                        ok = False 
                        amount_deb = 0; 
                        while ok == False and amount_deb <= 0 : 
                            try: 
                                amount_deb = float\
                                    (input('Enter the amount to debit\n>'))
                            except : 
                                print()
                                
                            if amount_deb <= 0 : 
                                print('\nThe amount entered must be positive!\n')
                            else : 
                                ok = True 
                        
                        self.Liste_Ewallet[index].DebitOperation(amount_deb)
                        self.Liste_Ewallet[index].Information()
                        
                    elif op == 2 :  
                        ok = False 
                        amount_cred = 0 ; 
                        while ok == False and amount_cred <= 0: 
                            try :
                                amount_cred = float\
                                    (input('Enter the amount to credit \n>'))
                            except:
                                print()
                            if amount_cred <= 0 : 
                                print('\nThe amount entered must\
                                      be positive!\n')
                            ok = True 
                        
                        self.Liste_Ewallet[index].CreditOp(amount_cred)
                        self.Liste_Ewallet[index].Information()
                        
                    elif op == 3 : 
                        self.Liste_Ewallet[index].Information()
                        self.graph_curr(index)
                        
                    elif op == 4 : 
                        choice = input('1. Buy\n2. Sell\n>')
                        Monaie_1 = input('Base >')
                        mon_1 = Monaie_1.strip()
                        monaie_1 = mon_1.upper()
                        Monaie_2 = input('Alternative >')
                        mon_2 = Monaie_2.strip()
                        monaie_2 = mon_2.upper()
                        montant = float(input('Amount >'))
                        wallet_1 = self.Liste_Ewallet[index]
                        cond_1 = self.verif_sold(monaie_2,index)
                        cond_2 = self.verif_sold(monaie_1,index)
                        if choice == '1':
                            if cond_1 == False :
                                try :
                                    wallet_1.accounts[monaie_1] = \
                                        wallet_1.accounts[monaie_1] + montant
                                    wallet_1.accounts[monaie_2] = \
                                        round(wallet_1.accounts[monaie_2] - \
                                              wallet_1.covertisseur_currencies\
                                                 (monaie_1,monaie_2,montant),2)
                                    print("\nAccount bal. ",\
                                          wallet_1.accounts)
                                except : 
                                    print('Currency entered does not exist!')
                            else :
                                print('Cannot debit {} as the balance\
                                      is zero!'.format(monaie_2))
                                
                        elif choice == '2':
                            if cond_2 == False :
                                try : 
                                    wallet_1.accounts[monaie_1] = \
                                        wallet_1.accounts[monaie_1] - montant
                                    wallet_1.accounts[monaie_2] =\
                                        round(wallet_1.accounts[monaie_2] + \
                                              wallet_1.covertisseur_currencies\
                                              (monaie_1,monaie_2,montant),2)
                                except:
                                    print('Currency entered does not exist')
                                print(" >",wallet_1.accounts)
                            else : 
                                print('Cannot debit {} as the sold is Zero!'\
                                      .format(monaie_1))               
                    
                    elif op == 5 : 
                         print('1. Modify Account \n2. Delete Account')
                         choice = input('\n>')
                         if choice == '1':
                             print('1. Modify ID\n2. Modify password')
                             choice_2 = input('\n>')
                             if choice_2 == '1' :
                                 new_Id = self.modif_Id()
                                 self.Liste_Ewallet[index].Id = new_Id
                                 print('The new ID : {} has been accepted!'\
                                       .format(new_Id))
                             elif choice_2 == '2': 
                                 new_code = self.modif_code()
                                 self.Liste_Ewallet[index].Pwd = new_code
                                 print('The new password : {} has been accepted!'\
                                       .format(new_code))
                             else :
                                 print('Invalid entry!')
                         elif choice == '2':
                             choice = input('Are you sure?\
                                            \n1. Yes \n2. No\n>')
                             if choice == '1': 
                                 correct_Iban = False 
                                 while correct_Iban == False : 
                                     #PRINT INFO AVEC TOUS LES IBAN POSSIBLE 
                                     Iban = input('Enter Iban to transfer >')
                                     cond,leng = self.verif_iban(Iban)
                                     if cond == True:
                                         print('Is the Iban correct?\
                                               \n1. Yes\n2. No')
                                         choice = input('\n>')
                                         if choice == '1':
                                             correct_Iban = True
                                         elif choice == '2':
                                             correct_Iban = False 
                                         else : 
                                             print('Invalid entry!')
                                     else : 
                                         print('Error ! minimum characters {} \
                                               or {} does not exist'.format(leng,Iban[:2]))
                                 wallet_remove = self.Liste_Ewallet[index]
                                 print('Your wallet has been deleted !\
                                       \nId : {}\nPassword : {}'.format\
                                           (wallet_remove.Id,wallet_remove.Pwd))
                                 #CHANGER le inamount en accounts 
                                 print('The amount on your wallet : {} has been transfered on the Iban : {}'.format(wallet_remove.InAmount,Iban))
                                 self.Liste_Ewallet.remove(wallet_remove)
                             else :
                                 print('Invalid entry!')
                                 
                    elif op == 6 : 
                        ## faire vendre et acheter peut acheter en toute les monnaie mais bitcon est en dollar de tte facon
                        op_crypto = input('1. BUY crypto\n2. SELL crypto')
                        curr = input('Enter the crypto currency >')
                        curr_strip = curr.strip()
                        curr_pursh = curr_strip.upper() # crypto pursh or sell not explicit
                        oper = self.choice_func(op_crypto)
                        curr_choice = input('Enter the currency in wich u want {} the {} >'.format(oper,curr_pursh))
                        sold_neg = self.verif_sold(curr_choice,index)
                        no_units = self.verif_unitCurr(curr_pursh,index)
                        wallet_crypto = self.Liste_Ewallet[index]
                        if op_crypto == '1':
                            if sold_neg == False : 
                                ## function montre les prix
                                amount = float(input('Amount in {} to purshase {} >'.format(curr_choice,curr_pursh)))
                                if amount <= wallet_crypto.accounts[curr_choice] :
                                    crypto_units = self.curr_units(curr_pursh,amount)
                                    print('unit of currency',crypto_units)
                                    # ajouter fees prelever par la banque 
                                    wallet_crypto.crypto[curr_pursh] = round(wallet_crypto.crypto[curr_pursh] + crypto_units,4)
                                    wallet_crypto.accounts[curr_choice] = wallet_crypto.accounts[curr_choice] - wallet_crypto.covertisseur_currencies(curr_choice,'USD',amount)
                                    print('montant debit',wallet_crypto.covertisseur_currencies(curr_choice,'USD',amount))
                                else :
                                    print("Error ! Don't have sufficient fund ")
                            else : 
                                print('Error ! No money on this account {}'.format(curr_choice))
                        elif op_crypto == '2' : 
                            if no_units == False: 
                                #imprimer le cour de la monnaie lors de la vente 
                                units_sell = float(input ('Enter the units of {} to sell >'.format(curr_pursh)))               
                                if units_sell < wallet_crypto.crypto[curr_pursh] :
                                    wallet_crypto.crypto[curr_pursh] = round(wallet_crypto.crypto[curr_pursh] - units_sell,4)
                                    #fonction qui calcule combien en dollar le mec gagne de la vente
                                    amount_dollar = self.amount_sell_crypto(curr_pursh,units_sell)
                                    wallet_crypto.accounts[curr_choice] = wallet_crypto.accounts[curr_choice] + wallet_crypto.covertisseur_currencies('USD',curr_choice,amount_dollar)
                                    print( wallet_crypto.covertisseur_currencies('USD',curr_choice,amount_dollar))
                                else:
                                    print('Error ! amount of {} entered not available'.format(curr_pursh))
                                    
                            else : 
                                print('Error ! no units of {}  available'.format(curr_pursh))
                            
                    elif op == 7:
                        stop_accountOp = True
                        print('\nBack to main menu')
                        
                    else :  
                        print('Invalid entry!') 
                
            else : 
                print('Wrong pin!\n')
        else:
            print('Wrong ID!\n')
    
# main function display on the console                        
def main():   
    stop = False 
    bank = Bank()  
    while stop == False: 
        Intro()
        op = 0
        try :
            op = int(input('>'))
        except: 
            print()
        if op == 1 : 
            bank.newWallet()
        elif op == 2 : 
            bank.accountOp()
        elif op == 3 :
            bank.saveBank()
            print('Thank you for using Ewallet Services')
            stop = True 
        elif op == 4: 
            pass
        else : 
            print('Invalid entry!')
    
    
if __name__ == "__main__":
    main()


voici le code que je dois mettre en interface graphique

il faut ajouter un fichier crypto:

import requests

# Cryptocurrency prices in USD powered by https://chasing-coins.com

 
# Bitcoin price
def BTC():
    BTCprice = requests.get ("https://chasing-coins.com/api/v1/std/coin/BTC/")
    return BTCprice.json()["price"]

# Ethereum price
def ETH():
    ETHprice = requests.get ("https://chasing-coins.com/api/v1/std/coin/ETH/")
    return ETHprice.json()["price"]

# Ripple price
def XRP():
    XRPprice = requests.get ("https://chasing-coins.com/api/v1/std/coin/XRP/")
    return XRPprice.json()["price"]

# Tether price
def USDT():
    USDTprice = requests.get ("https://chasing-coins.com/api/v1/std/coin/USDT/")
    return USDTprice.json()["price"]

# Bitcoin Cash price
def BCH():
    BCHprice = requests.get ("https://chasing-coins.com/api/v1/std/coin/BCH/")
    return BCHprice.json()["price"]

# Bitcoin SV price
def BSV():
    BSVprice = requests.get ("https://chasing-coins.com/api/v1/std/coin/BSV/")
    return BSVprice.json()["price"]

# Litecoin price
def LTC():
    LTCprice = requests.get ("https://chasing-coins.com/api/v1/std/coin/LTC/")
    return LTCprice.json()["price"]

# Binance Coin price
def BNB():
    BNBprice = requests.get ("https://chasing-coins.com/api/v1/std/coin/BNB/")
    return BNBprice.json()["price"]

# EOS price
def EOS():
    EOSprice = requests.get ("https://chasing-coins.com/api/v1/std/coin/EOS/")
    return EOSprice.json()["price"]

# Tezos price
def XTZ():
    XTZprice = requests.get ("https://chasing-coins.com/api/v1/std/coin/XTZ/")
    return XTZprice.json()["price"]


BTC = round(float(BTC()),2)
ETH = round(float(ETH()),2)
XRP = round(float(XRP()),2)
USDT = round(float(USDT()),2)
BCH = round(float(BCH()),2)
BSV = round(float(BSV()),2)
LTC = round(float(LTC()),2)
BNB = round(float(BNB()),2)
EOS = round(float(EOS()),2)
XTZ = round(float(XTZ()),2)


et maintenant je n'ai que souhaité faire des boutons afin de mettre en place ma fonction Intro() mais déjà là je n'arrive pas à executer...

Saurais tu comment faire ?
import tkinter as tk
 

def Intro ():
    global root
    def ola():
        print("1 : Create a new profile")
        root.destroy()
    def al():
        print("2 : Access to an existing account")
        root.destroy()
    def ala():
        print("3 : Quit Ewallet Services")
        root.destroy()
    
    root.withdraw()
    
    fenTop = tk.Toplevel()
    
    loulou = tk.Message(fenTop, text =" Welcome to Ewallet Services Which action would you like to take? " 
                      

    
    btnOui = tk.Button(fenTop, text="1 : Create a new profile", command= ola)
    btnOui.pack()

    btnNon = tk.Button(fenTop, text="2 : Access to an existing account", command=al)
    btnNon.pack()

    btnOon = tk.Button(fenTop, text="3 : Quit Ewallet Services", command=ala)
    btnOon.pack()

root = tk.Tk()
 
canva = tk.Canvas(root, width=500, height=500)
canva.pack()
 
btnQuitter = tk.Button(root, text="Quitter", command=Intro)
btnQuitter.pack()
 
root.mainloop()


ou si c'est la mauvaise méthode merci de me dire comment je peux m'y prendre autrement ! :)

Merci !
0
Phil_1857 Messages postés 1872 Date d'inscription   Statut Membre Dernière intervention   168
 
Chez moi, ca marche à condition de fermer la parenthèse à la fin de loulou = (

et de ne pas mettre root.destroy() à la fin des fonctions ola et al sinon, la fenêtre se ferme de

suite !

Et donc ça écrit bien 1 : Create a new profile et 2 : Access to an existing account dans la fenetre

d' exécution du code
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
Programmeurnul Messages postés 15 Date d'inscription   Statut Membre Dernière intervention  
 
mais est-ce la bonne méthode pour pouvoir valider tout mon code comme ça ?
0
Programmeurnul Messages postés 15 Date d'inscription   Statut Membre Dernière intervention  
 
ce que je ne comprends pas, c'est est-ce que je peux mettre tout mon code principal sous cette forme et l'executer depuis l'interface en faisant de cette manière ?
0
Phil_1857 Messages postés 1872 Date d'inscription   Statut Membre Dernière intervention   168
 
Bah, pourquoi pas ?

Mais moi, je simplifierais en ne créant pas de fenêtre secondaire

(fenTop = tk.Toplevel())

je mettrais tous les boutons dans la fenêtre principale et le bouton Quitter ne servirait qu'à

quitter ...
0
Programmeurnul Messages postés 15 Date d'inscription   Statut Membre Dernière intervention  
 
de cette manière ?
import tkinter as tk
 

def Intro ():
    global root
    def ola():
        print("1 : Create a new profile")
    def al():
        print("2 : Access to an existing account")
    def ala():
        print("3 : Quit Ewallet Services")
        root.destroy()
    
    root.withdraw()
    
    
    loulou = tk.Message(root, text ="Which action would you like to take? " ) 
    loulou.pack()

    btnOui = tk.Button(root, text="1 : Create a new profile", command= ola)
    btnOui.pack()

    btnNon = tk.Button(root, text="2 : Access to an existing account", command=al)
    btnNon.pack()

    btnOon = tk.Button(root, text="3 : Quit Ewallet Services", command=ala)
    btnOon.pack()

root = tk.Tk()
 
canva = tk.Canvas(root, width=1500, height=800)
canva.pack()
 
btnQuitter = tk.Button(root, text="Bienvenue sur Ewallet", command=Intro)
btnQuitter.pack()
 
root.mainloop()



pour l'instant rien ne me sort mais je vais essayer de me débrouiller pour passer d'une fonction à l'autre.

Merci
0
Programmeurnul Messages postés 15 Date d'inscription   Statut Membre Dernière intervention  
 
mais j'ai l'impression que mon code ne va pas interagir avec le reste, ça va marcher ?
0
Phil_1857 Messages postés 1872 Date d'inscription   Statut Membre Dernière intervention   168
 
Non, comme ça, tout simplement:
et là, ca sort bien

import tkinter as tk

def ola():
    print("1 : Create a new profile")

def al():
    print("2 : Access to an existing account")

def ala():
    print("3 : Quit Ewallet Services")
    root.destroy()

root = tk.Tk()
l1 = tk.Label(root, text="Welcome to Ewallet Services Which action would you like to take?", fg = 'black')
l1.pack()

canva = tk.Canvas(root, width=500, height=500)
canva.pack()

btnOui = tk.Button(root, text="1 : Create a new profile", command= ola)
btnOui.pack()

btnNon = tk.Button(root, text="2 : Access to an existing account", command=al)
btnNon.pack()

btnQuitter = tk.Button(root, text="Quitter", command=ala)
btnQuitter.pack()

root.mainloop()
0
Phil_1857 Messages postés 1872 Date d'inscription   Statut Membre Dernière intervention   168
 
As-tu copié et testé mon code ?

Est-ce que ca marche chez toi ?

Après, il faut intégrer ton code dedans, mettre ce qu'il faut dans les bonnes fonctions, il n'y a pas de raisons que ca ne marche pas …

Evidemment il faut oublier les print() qui écrivent dans la console (la fenêtre noire)
et mettre une zone de texte dans le Canvas si il y a des messages ou des résultats à sortir

D'ailleurs, moi, les programmes avec interface graphique, je les appelle toto.pyw au lieu de toto.py, comme ça, la fenêtre console ne s'affiche pas, l'interface démarre directement
0
Programmeurnul Messages postés 15 Date d'inscription   Statut Membre Dernière intervention  
 
est-ce que ce serait possible d'avoir des explications orales par un skype ou un zoom ? je n'arrive pas très bien à suivre comment je peux intégrer mes fonctions dans ce code
0
Programmeurnul Messages postés 15 Date d'inscription   Statut Membre Dernière intervention  
 
est ce que ca signifie que je devrais reprendre mes fonctions et reprendre le code et remettre ca de la même manière qu'avant ? parce que j'ai l'impression que c'est ce que j'ai essayé de faire et que je n'arrivais pas à faire autrement
0
Programmeurnul Messages postés 15 Date d'inscription   Statut Membre Dernière intervention  
 
import tkinter as tk

def ola():
    new_client()

def al():
    print("2 : Access to an existing account")

def ala():
    print("3 : Quit Ewallet Services")
    root.destroy()

root = tk.Tk()
l1 = tk.Label(root, text="Welcome to Ewallet Services Which action would you like to take?", fg = 'black')
l1.pack()

canva = tk.Canvas(root, width=500, height=500)
canva.pack()

btnOui = tk.Button(root, text="1 : Create a new profile", command= ola)
btnOui.pack()

btnNon = tk.Button(root, text="2 : Access to an existing account", command=al)
btnNon.pack()

btnQuitter = tk.Button(root, text="Quitter", command=ala)
btnQuitter.pack()



def new_client():
    master = tk.Tk()
    tk.Label(master, 
         text="Enter an ID to open an account").grid(row=0)
    tk.Label(master, 
         text="Enter amount").grid(row=1)

    e1 = tk.Entry(master)
    e2 = tk.Entry(master)

    e1.grid(row=0, column=1)
    e2.grid(row=1, column=1)

    tk.Button(master, text='Quit', command=master.quit).grid(row=3, column=0, sticky=tk.W, pady=4)
    tk.Button(master, text='Show', command=master.show_entry_fields).grid(row=2, column=1, sticky=tk.W, pady=4)

root.mainloop()


j'ai essayé d'ajouter des lignes de code mais la je n'arrive pas a valider mes input, comment puis-je faire ?
0
Phil_1857 Messages postés 1872 Date d'inscription   Statut Membre Dernière intervention   168
 
Bonjour Programmeurnul,

Que veux tu dire: je n'arrive pas a valider mes input ?


Compliqué ton code, tu as des boutons sur la fenêtre et dans la fonction new_client tu en refait d'autres et en plus tu appelle ola() qui appelle new_client, pourquoi ne pas appeler new_client() directement

Plus besoin de la fonction ala(), ci-dessous le code amélioré avec écriture dans la fenêtre, pas dans la fenêtre console:

#21/05/2020 11:26:19

from tkinter import *

def new_prof():

    dr.delete(1.0, END)
    dr.insert(0.0,'Create a new profile\n')

def access_to_account():

    dr.delete(1.0, END)
    dr.insert(0.0,'Access to an existing account\n')


root = Tk()
root.title('Ewallet Services')
root.geometry('400x300+250+100')

l1 = Label(root, text="Welcome to Ewallet Services Which action would you like to take?", fg = 'black')
l1.pack()

dr = Text(root, width = 30, height = 12)
dr.pack()

btnOui = Button(root, text="Create a new profile", command= new_prof)
btnOui.pack()

btnNon = Button(root, text="Access to an existing account", command=access_to_account)
btnNon.pack()

btnQuitter = Button(root, text="Quitter", command=root.quit)
btnQuitter.pack()

root.mainloop()
0
Programmeurnul Messages postés 15 Date d'inscription   Statut Membre Dernière intervention  
 
mais justement ce que je veux est que lorsque je clique sur create a new profile, je veux pouvoir insérer deux nouvelles variables (un string et un int) et que je puisse les récupérer pour pouvoir les intégrer à mes fonctions de mon code.
0
Programmeurnul Messages postés 15 Date d'inscription   Statut Membre Dernière intervention  
 
donc je devrais depuis les deux fonctions new_prof and aces_to_account ajouter mes deux Label dans le root et essayer de récupérer à partir de là ?
0
Phil_1857 Messages postés 1872 Date d'inscription   Statut Membre Dernière intervention   168
 
Déjà, as tu récupéré et testé mon code et est-ce qu'il fonctionne ?
0
Programmeurnul Messages postés 15 Date d'inscription   Statut Membre Dernière intervention  
 
Justement j'essaie mais je ne comprends pas très bien. J'ai envoyé un message mais il a disparu je ne sais pas ou, peut être l'ai-je pas envoyé par mégarde. Je vais donc le récrire ici :

Avec votre méthode je peux donc rester sur la fenêtre principale tout le long de mon programme. mais il me faut deux "labels" ou je ne sais pas quoi qui permettrait à l'utilisateur d'insérer son ID ainsi que son montant d'argent à investir.
Par conséquent il me faudrait un "bouton?" qui me permettrait lorsqu'on clique dessus de sauvegarder les valeurs insérées. une fois cela fait je devrais pouvoir afficher ma fonction info() qui avec les valeurs insérées précédemment permet d'afficher les informations du compte de l'utilisateur et un dernier bouton qui permettrait de revenir à la fenêtre de base ou de quitter l'interface.

Je ne comprends pas très bien comment pouvoir mettre cela en place mais si vous pouvez m'expliquer pour cette partie 1 (create a new wallet) je devrais uniquement répliquer la méthode sur tout l'ensemble du code, ce qui serait très long mais me permettrait de m'exercer à bien comprendre le fonctionnement.

Dans la mesure du possible, pourriez vous m'expliquer comment pouvoir insérer et stocker mes valeurs et effectuer ce que je souhaite ? Je vous suis très reconnaissant.

Merci pour votre aide
0
Programmeurnul Messages postés 15 Date d'inscription   Statut Membre Dernière intervention  
 
oui il fonctionne j'essaie de combiner le votre avec ce que j'ai envie de faire mais je peine.
from tkinter import *

def new_prof():

    dr.delete(1.0, END)
    dr.insert(0.0, "Enter an ID to open an account\n")
    dr.insert(1.0,'Create a new profile\n')
    dr.insert
    tk.Label(root, text="Enter amount").grid(row=2)

    e1 = tk.Entry(master)
    e2 = tk.Entry(master)

    e1.grid(row=1, column=1)
    e2.grid(row=2, column=1)

    tk.Button(master, text='Quit', command=master.quit).grid(row=3, column=0, sticky=tk.W, pady=4)
    tk.Button(master, text='Show', command=master.show_entry_fields).grid(row=3, column=1, sticky=tk.W, pady=4)


def access_to_account():

    dr.delete(1.0, END)
    dr.insert(0.0,'Access to an existing account\n')
    


root = Tk()
root.title('Ewallet Services')
root.geometry('500x400+250+100')

l1 = Label(root, text="Welcome to Ewallet Services Which action would you like to take?", fg = 'black')
l1.pack()

dr = Text(root, width = 30, height = 12)
dr.pack()

btnOui = Button(root, text="Create a new profile", command= new_prof)
btnOui.pack()

btnNon = Button(root, text="Access to an existing account", command=access_to_account)
btnNon.pack()

btnQuitter = Button(root, text="Quitter", command=root.quit)
btnQuitter.pack()

root.mainloop()



Merci beaucoup pour votre aide parce que je nage dans ces codes je ne comprends pas vraiment comment obtenir ce que je veux.
0
Phil_1857 Messages postés 1872 Date d'inscription   Statut Membre Dernière intervention   168
 
Bonjour Programmeurnul ,

Je vois que dans ton programme en mode console, on affiche un menu:

\n\n 1 : Create a new profile \
\n 2 : Access to an existing account \
\n 3 : Quit Ewallet Services'


Et si, par exemple, on entre "1", on appelle la fonction correspondante:

if op == 1 :
bank.newWallet()


Donc le bouton "Create a new profile" devrait faire pareil:

btnOui = Button(root, text="Create a new profile", command= bank.newWallet())

Non ?
0