tkinter and scroll

John Grayson johngrayson at home.com
Wed Dec 27 14:41:23 EST 2000


In article <slrn94k7u8.14h.jp at localhost.localdomain>,
  jp at ulgo.koti.com.pl wrote:
> I want to create window with:
> - text (diffrent fonts)
> - images
> - buttons
> and scroll it (becouse it can be larger than screen)
> Is it possible to do it in Tkinter?
>
> from tutorial: (scrollbar)
>
> "This widget is used to implement scrolled listboxes, canvases, and
>  text fields."
>
> what about buttons and other widgets? what about all-in-one ?
>
> If it's impossible with Tkinter - is it possible with pygtk?
>


How about using a Text widget -- you can embed anything in that...

from Tkinter import *

root = Tk()
root.title('Text')
text = Text(root, height=26, width=50)
scroll = Scrollbar(root, command=text.yview)
text.configure(yscrollcommand=scroll.set)
text.tag_configure('bold_italics', font=('Verdana', 12, 'bold',
'italic'))
text.tag_configure('big', font=('Verdana', 24, 'bold'))
text.tag_configure('color', foreground='blue', font=('Tempus Sans ITC',
14))
text.tag_configure('groove', relief=GROOVE, borderwidth=2)
text.tag_bind('bite', '<1>',
              lambda e, t=text: t.insert(END, "I'll bite your legs
off!"))

text.insert(END, 'Something up with my banter, chaps?\n')
text.insert(END, 'Four hours to bury a cat?\n', 'bold_italics')
text.insert(END, 'Can I call you "Frank"?\n', 'big')
text.insert(END, "What's happening Thursday then?\n", 'color')
text.insert(END, 'Did you write this symphony in the shed?\n', 'groove')
button = Button(text, text='I do live at 46 Horton terrace')
text.window_create(END, window=button)
photo=PhotoImage(file='lumber.gif')
text.image_create(END, image=photo)
text.insert(END, 'I dare you to click on this\n', 'bite')
text.pack(side=LEFT, fill=BOTH, expand=YES)
scroll.pack(side=RIGHT, fill=Y)

root.mainloop()

You'll have to get your own lumber.gif image...

    John Grayson


Sent via Deja.com
http://www.deja.com/



More information about the Python-list mailing list