Bonjour, je suis en train de réaliser un petit editeur de texte pour m'amuser et apprendre un peu plus le python.

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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
from Tkinter import *
import tkFileDialog
from tkFileDialog import *
 
 
class descxmleditor:
    from Tkinter import Toplevel
    import tkFileDialog
    from tkFileDialog import *
    import os
 
    def __init__(self, root=None):
        #root = root
        self.root = root
        self.menubar = Menu(root)
        self.top = top = Toplevel(root, menu=self.menubar)
        self.product_dir = self.os.getcwd()
        print self.product_dir      
        #call createmenubar
        self.createmenubar()
 
        #call createwidgettext
        self.createText()
 
        print self.root.cget("width")
        print self.root.cget("height")
 
        self.top.protocol("WM_DELETE_WINDOW", self.close)
 
    def close(self):
        self.root.quit()
 
    def createText(self):
        self.textboxFrame = textboxFrame = Frame(self.root)
        self.text = text = Text(textboxFrame)
        rightScrollbar = Scrollbar(textboxFrame, orient=VERTICAL, command=text.yview)
        text.configure(yscrollcommand = rightScrollbar.set)
        bottomScrollbar = Scrollbar(textboxFrame, orient=HORIZONTAL, command=text.xview)
        text.configure(xscrollcommand = bottomScrollbar.set)
        bottomScrollbar.pack(side=BOTTOM, fill=X)
        rightScrollbar.pack(side=RIGHT, fill=Y)
        #text.configure(witdh = self.root.width - 10)
        #text.configure(height = self.root.height - 10)
 
        text.focus_set()
        text.pack(side = TOP)
        textboxFrame.pack(side=TOP)
 
 
    def createmenubar(self):
 
        self.menubar = Menu(self.root)
 
        # create a pulldown menu, and add it to the menu bar
        self.filemenu = Menu(self.menubar, tearoff=0)
        self.filemenu.add_command(label="New",)
        self.filemenu.add_command(label="Open", command = self.open_descxml)
        self.filemenu.add_command(label="Save")
        self.filemenu.add_separator()
        self.filemenu.add_command(label="Exit")
        self.menubar.add_cascade(label="File",menu=self.filemenu)
 
        # create more pulldown menus
        self.editmenu = Menu(self.menubar, tearoff=0)
        self.editmenu.add_command(label="Cut")
        self.editmenu.add_command(label="Copy")
        self.editmenu.add_command(label="Paste")
        self.editmenu.add_separator()
        self.editmenu.add_command(label="Search")
        self.menubar.add_cascade(label="Edit", menu=self.editmenu)
 
        self.toolsmenu = Menu(self.menubar, tearoff =0)
        self.toolsmenu.add_command(label="Test Descxml",command = self.test_descxml)
        self.menubar.add_cascade(label="Tools", menu=self.toolsmenu)
 
        self.helpmenu = Menu(self.menubar, tearoff=0)
        self.helpmenu.add_command(label="About")
        #helpmenu.add_command(label="Trace")
        self.helpmenu.add_command(label="Visit WebSite")
        self.menubar.add_cascade(label="Help", menu=self.helpmenu)
        #self.base_helpmenu_length = self.menudict['help'].index(END)
        # display the menu
        self.root.config(menu=self.menubar)
 
    def open_descxml(self):
        self.opendescxml=tkFileDialog.askopenfilename(filetypes = [("Fichiers descxml", "*.descxml")])
        f=open(self.opendescxml)
        l = 0
        for lines in f:
            l = l+1
            self.text.insert(str(l)+'.0', lines)
 
    def test_descxml(self):
        self.check_path = IntVar()
        self.root_test=Tk()
        self.root_test.title("Valide your descxml file")
        self.test_frame = Frame(self.root_test)
        self.lbl_browsepath = Label(self.test_frame, text="Enter path where is DymanicDialog :")
        self.lbl_browsepath2 = Label(self.test_frame, text="(e.g : \tools\DymanicDialog\DymanicDialog.bat)")
        self.entry_path=Entry(self.test_frame)
        self.entry_path.configure(width =50)
        self.browsepath = Button(self.test_frame, text="...", command = self.browsepath)
        self.ButtonTest = Button(self.test_frame, text = "Test Descxml", command =self.starttest)
        self.SavePath = Checkbutton(self.test_frame,variable=self.check_path, text = " Save path")
        self.SavePath.bind('<Button-1>', self.event_check)
 
        self.lbl_browsepath.grid(row =0)
        self.lbl_browsepath2.grid(row =1, column =0, columnspan =2)
        self.entry_path.grid(row =2, column =0, padx = 10)
        self.browsepath.grid(row =2, column =1, padx =20)
        self.SavePath.grid(row =3, column =0, padx =10)
        self.ButtonTest.grid(row =4)
        self.test_frame.pack(side = TOP)
        self.root_test.mainloop()
 
    def browsepath(self):
        self.path = tkFileDialog.askopenfilename(filetypes = [("All Files", "*.*")])
        if self.entry_path == None:
            self.entry_path.insert(END,self.path)
        else:
            self.entry_path.delete(0,END)
            self.entry_path.insert(END,self.path)
 
    def starttest(self):
        print self.check_path.get()
        if self.check_path.get() == 1:
            print "project saved"
            write_editor_ini()
        else:
            pass
        self.os.system("start " + str(self.entry_path.get()))
 
    def event_check(self, evt):
        print self.check_path.get()
        #if self.check_path.get() == 1:
 
            #self.check_path = 1
        #else:
           #print self.check_path.get()
            #self.check_path = 0
 
 
    def write_editor_ini(self):
        self.g=open(product_dir + "\editor.ini","w+")
        #InstallDir = opInstallDir.replace("/","\\")
        self.g.write("Product_Dir=" + self.product_dir + "\n")
        self.g.write("SavePath=" + self.entry_path.get() +"\n")
        self.g.close()
 
def main():
    root = Tk()
    root.title("DESCXML Editor")
    root.config(width=300)
    root.config(height=100)
    edit = descxmleditor(root=root)
    root.mainloop()
    #root.destroy()
 
if __name__ == '__main__':
    main()
ma premiere question est comment puis-je faire pourque mon widget texte soit agrandi si on agrandi la fenêtre principale?

ensuite, j'ai mis une scrollbar vertical et horizontal dans mon widget text, mais seule la scrollbar vertical marche. Comment puis-je y remedier?

Merci de votre aide