Bonjour,

j'ai un code qui contient un menu déroulant et un autre code qui contient une barre de menu avec des images. Je souhaiterai en faire un seul code. Pourriez-vous m'indiquer comment faire, svp?


Code1 :

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
33
34
35
36
37
38
39
40
41
from tkinter import *
from tkinter import filedialog
from tkinter.filedialog import askopenfile
 
filename = None
 
def newFile():
    global filename
    filename = "Untitled"
    text.delete(0.0, END)
 
def openFile():
    global filename
    file = askopenfile(parent=root,title='Select a File')
    filename = file.name
    t = file.read()
    text.delete(0.0, END)
    text.insert(0.0, t)
    file.close()
 
root = Tk()
 
root.title("MonkeyCode Editor")
root.minsize(width=800, height=600)
root.maxsize(width=800, height=600)
 
text = Text(root, width=400, height=200)
text.pack()
 
 
menubar = Menu(root)
filemenu = Menu(menubar)
filemenu.add_command(label="New", command=newFile)
filemenu.add_command(label="Open", command=openFile)
filemenu.add_separator()
filemenu.add_command(label="Quit", command=root.destroy)
menubar.add_cascade(label="File", menu=filemenu)
 
root.config(menu=menubar)
 
mainloop()
code 2 :

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
33
34
35
36
37
38
39
40
41
42
43
#! /usr/bin/python
# File: ToolbarEx.py
 
from tkinter import *
from PIL import Image, ImageTk
 
class App():
    def __init__(self):
        self.root = Tk()
 
        # Create the toolbar as a frame
        self.toolbar = Frame(self.root, borderwidth=2, relief='raised')
 
        # Load all the images first as PNGs and use ImageTk to convert
        # them to usable tkinter images.
        self.img1 = Image.open('NewIcon.png')
        self.useImg1 = ImageTk.PhotoImage(self.img1)
 
 
        # Set up all the buttons for use on the toolbars.
        newBtn = Button(self.toolbar, image=self.useImg1, command=self.callback)
        newBtn.pack(side=LEFT, fill=X)
 
        # Add the toolbar
        self.toolbar.pack(side=TOP, fill=X)
 
        # Set up a Text box and scroll bar.
        self.scrollbar = Scrollbar(self.root)
        self.scrollbar.pack(side=RIGHT, fill=Y)
 
        self.text = Text(self.root)
        self.text.pack()
 
        self.text.config(yscrollcommand=self.scrollbar.set)
        self.scrollbar.config(command=self.text.yview)
 
 
    def callback(self):
        print ("A button was pressed")
 
if __name__ == "__main__":
    a = App()
    a.root.mainloop()

Cordialement,
Arsène