[AIDE, PROBLEME] Tekinter IF dans une fonction

RaphLopes -  
RaphLopes Messages postés 1 Date d'inscription   Statut Membre Dernière intervention   -
Bonjour, j'ai un probleme sur mon script python, imposible de mettre un if ans une fonction,je peut donc pas verifier le entry input de tekinter

voici mon code python
from tkinter import *
import os
import sys
import subprocess

#script python hors tkinter
def run_program():
 choix = choix_option.get()
 if choix.option.get()== 1:
  execfile('/home/pi/Desktop/raph/sources/ports.py')
 

#cretion fenetre
window = Tk()

#personaliser fenetre
window.title("Hacking Tools")
window.geometry("720x720")
window.minsize(480,480)
window.config(background='black')

#frame
 #frame des options
frameOptions = Frame(window, bg='black')
 #frame de validation
frameValidation = Frame(window, bg='black')

#text
titre = Label(window, text="Choisis ton option", font=("20"), bg='black', fg='white')
titreOption1 = Label(frameOptions, text="1-Scan de ports", font=("10"), bg='black', fg='white')
titreOption2 = Label(frameOptions, text="2-Ping", font=("10"), bg='black', fg='white')

#choix
choix_option = Entry(frameValidation)
button_choix=Button(frameValidation, text="Validation de votre choix",command=run_program)

#affichage
button_choix.pack()
choix_option.pack(side='bottom')
titre.pack()
titreOption1.pack()
titreOption2.pack()
frameValidation.pack(side='bottom')
frameOptions.pack(side='top')
window.mainloop() 
A voir également:

1 réponse

yrokoi
 
Bonjour,

Plusieurs problèmes.
Avec une indentation de code à 1 seul caractère, tu vas au-devant de futurs problèmes, la convention en python est de 4 caractères.

def run_program():
 choix = choix_option.get()
 if choix.option.get()== 1:
  execfile('/home/pi/Desktop/raph/sources/ports.py')


choix est déjà la valeur récupérée, et si tu avais affiché ce que ça contient, tu aurais pu voir que c'était une chaine de caractères contenant '1'. Alors forcément str n'ayant pas d'attributs 'options', tu obtiens une erreur.

Ta fonction devrait alors être.

def run_program():
    choix = choix_option.get()
    if choix == '1':
        execfile('/home/pi/Desktop/raph/sources/ports.py')


Reste à déterminer pourquoi exécuter un fichier py, alors que l'importer serait plus sain...
0
RaphLopes Messages postés 1 Date d'inscription   Statut Membre Dernière intervention  
 
Super merci de ta reponse
0