Outils pour utilisateurs

Outils du site


texte_redim

Une fenêtre texte multilignes avec ascenseurs qui suit le redimensionnement de la fenêtre

Ce petit code que j'ai mis ici pour ne pas avoir à chercher la prochaine fois, résout 2 difficultés:

  • comment accrocher les 2 ascenseurs horizontaux et verticaux à un widget “Text” multilignes
  • comment faire en sorte que le widget Text accompagné de ses ascenseurs suive le redimensionnement de la fenêtre

Voilà le code:

#!/usr/bin/python
# -*- coding: utf-8 -*-
 
from Tkinter import *
 
class Edtexte(Frame):
    def __init__(self, master=None):
        Frame.__init__(self, master, width=600, height=480)
 
        self.grid(sticky=N+E+S+W)
 
        top=self.winfo_toplevel()
        top.rowconfigure(0, weight=1)
        top.columnconfigure(0, weight=1)
        self.rowconfigure(0, weight=1)
        self.columnconfigure(0, weight=1)
 
        self.edSBv = Scrollbar(self, orient=VERTICAL)
        self.edSBh = Scrollbar(self, orient=HORIZONTAL)
        self.edt = Text(self, wrap=NONE, yscrollcommand = self.edSBv.set, xscrollcommand = self.edSBh.set)
        self.edSBv.config(command=self.edt.yview)
        self.edSBh.config(command=self.edt.xview)
        self.edt.grid(row=0, column=0, sticky=N+E+S+W)
        self.edSBv.grid(row=0, column=1, sticky=N+S+E)
        self.edSBh.grid(row=1, column=0, sticky=S+E+W)
 
 
 
fen = Tk()
app = Edtexte(fen)
fen.mainloop()

texte_redim.txt · Dernière modification: 2008/05/12 07:13 de tyrtamos

Outils de la page