[Tkinter-discuss] Need help with a text + scrollbar widget and expansion

Mannequin* mannslists at invigorated.org
Mon Mar 20 19:10:41 CET 2006


Hi all,

I'm new to the list, and I have a question about how I can get a text + 
scrollbar widget to expand properly in their frame.

I'll first give you the sample code, then I'll link to images of the 
problem.

*********************************************************************

from Tkinter import *

APP_NAME = "Spurgeon"
APP_VERSION = "0.10"
BIBLE_BOOKS = ["Genesis", "Exodus", "Leviticus", "Numbers"]

class Spurgeon (Frame):
	"""Hopefully a class to create the Tkinter interface"""
	def __init__ (self, parent = None):
		"""Creates main window and widgets"""
		self.root = Tk ()
		self.root.title (APP_NAME + ' ' + APP_VERSION)
		self.root.config (borderwidth = 3)

		Frame.__init__ (self, parent)
		self.pack (fill = "both", expand = "yes")

		self.make_widgets ()

	def make_widgets (self):
		"""Create the widgets for the main window"""
		# Create the main menu
		self.mainmenu = Menu (self.root)
		
		# Create the File menu
		self.file_menu = Menu (self.mainmenu, tearoff = 0)
		self.file_menu.add_command (label = "Open", underline = 0)
		self.file_menu.add_separator ()
		self.file_menu.add_command (label = "Quit", underline = 0, command = 
self.root.quit)
		self.mainmenu.add_cascade (label = "File", menu = self.file_menu, 
underline = 0)

		# Create the Edit menu
		self.edit_menu = Menu (self.mainmenu, tearoff = 0)
		self.edit_menu.add_command (label = "Cut", underline = 2)
		self.edit_menu.add_command (label = "Copy", underline = 0)
		self.edit_menu.add_command (label = "Paste", underline = 0)
		self.edit_menu.add_command (label = "Delete", underline = 0)
		self.mainmenu.add_cascade (label = "Edit", menu = self.edit_menu, 
underline = 0)
		
		# Create the Help menu
		self.help_menu = Menu (self.mainmenu, tearoff = 0)
		self.help_menu.add_command (label = "About", underline = 0)
		self.mainmenu.add_cascade (label = "Help", menu = self.help_menu, 
underline = 0)
		
		# Display the main menu
		self.root.config (menu = self.mainmenu)
		
		# Create the left frame
		self.tool_frame = Frame (self, borderwidth = 2)
		self.tool_frame.pack (side = LEFT, anchor = NW)
		Label (self.tool_frame, text = "Left frame").pack ()

		# Create the right frame
		self.view_frame = Frame (self, borderwidth = 2)
		self.view_frame.pack (side = RIGHT, expand = "yes", fill = "both")
		# Create the area where the Bible is viewed from
		self.bible_scroll = Scrollbar (self.view_frame)
		self.bible_view = Text (self.view_frame, relief = SUNKEN)
		self.bible_scroll.config (command = self.bible_view.yview)
		self.bible_view.config (yscrollcommand = self.bible_scroll.set)
		self.bible_view.pack (side = LEFT, fill = "both", expand = "yes")
		self.bible_scroll.pack (side = RIGHT, fill = Y, expand = "yes", anchor 
= W)

if (__name__ == "__main__"):
	a = Spurgeon ()
	a.mainloop ()

*********************************************************************

Now, if you run this, you'll notice that when you expand the window 
horizontally ( <---> ) that the text + scrollbar widget doesn't expand 
with the window.

Here is a screenshot of the problem to illustrate what I'm talking about:

<http://mannequin.invigorated.org/images/problem.png>

I hope I've given enough information here to be helpful.

By the way, is there anyway to enhance the look of the Tkinter widgets 
under Linux using what comes standard with Python. I'm trying to stay as 
standard as I possibly can.

Thanks!
-M.


More information about the Tkinter-discuss mailing list