Bonsoir.

Je souhaiterai, avec l'aide du module tkinter créer des fenetres interactives mais j'avoue avoir beaucoup de mal.
J'ai créé une fenetre qui contient un bouton qui me permet d'ouvrir une deuxieme fenetre. Dans la premiere fenetre j'ai pus créer des widget fram mais je n'arrive pas à en créer dans la deuxieme fenetre.

Voici mon code:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
32
 
 
# -*-coding:Latin-1 -*
import os
from random import *
from tkinter import *
 
# Configuration de la fenetre principale
racine0=Tk()
racine0.title("ANALYSE")
racine0.geometry("400x300+10+10")
racine0.minsize(400,300)
racine0.maxsize(400,300)
racine0.positionfrom("user")
racine0.protocol("WM_DELETE_WINDOW",racine0.destroy)
 
#configuration fenetre 2
 
def top():
     feneU=Toplevel(racine0)
     feneU.title("ANALYSE2")
labelU=Label(top,text="AJOUT")
 
# Creation des widget frame dans la fenetre principale
 
fram=Frame(racine0,borderwidth=2,relief=GROOVE)
Label(fram,text=" AJOUT1").pack(side=TOP)
Button(fram, text="USA", fg='navy', command=top).pack(side="left", padx=50, pady=5)
 
 
racine0.mainloop()
os.system("pause")
Et voila le message d'erreur

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
 
 
Traceback  (most recent call last):
   File "C:/Python32/essai Tkinter2.py", line 21, in <module>
     labelU=Label(top, text="AJOUT")
   File "C:\Python32\lib\tkinter\__init__.py", line 2459, in __init__
     Widget.__init__(self, master, 'label', cnf, km)
   File "C:\Python32\lib\tkinter\__init__.py", line 1951, in __init__
     BaseWidget._setup(self, master, cnf)
   File "C:\Python32\lib\tkinter\__init__.py", line 1929, in _setup
     self.tk = master.tk
AttributeError: 'function'  object has no attribute  'tk'