954,515 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

menubar and toolbar

how to add a seperating line between menubar and toolbar in Python using Tkinter. is that possible using Tkinter. also how to add vertical seperating line to seperate toolbar buttons in toolbar.

please help me out from this problem.

katharnakh
Posting Whiz in Training
237 posts since Jan 2006
Reputation Points: 19
Solved Threads: 34
 

not too sure what you meant mate but www.pythonware.com has a great documentation for Tkinter, here's a link to a page on the site that may or may not help you:
http://www.pythonware.com/library/tkinter/introduction/x953-menus.htm

a1eio
Junior Poster
141 posts since Aug 2005
Reputation Points: 26
Solved Threads: 25
 

The toolbar in Tkinter is usually a frame with buttons added below the menubar. Depending how you configure the frame there should be a visible separation. If you want to separate the toolbar, you could use two frames properly packed. Here is an example ...

# the toolbar is a frame with buttons and is usally put right below the menubar

from Tkinter import *

def callback(what=None):
    print "callback =", what
    if what == 'red':
        b1.config(bg="#ff0000")
    if what == 'blue':
        b2.config(bg="#0000ff")

class Curry:
    """handles arguments for callback functions"""
    def __init__(self, callback, *args, **kwargs):
        self.callback = callback
        self.args = args
        self.kwargs = kwargs

    def __call__(self):
        return apply(self.callback, self.args, self.kwargs)

root = Tk()

# create the menubar
menubar = Menu(root)

filemenu = Menu(menubar)
filemenu.add_command(label="Open", command=Curry(callback, "open"))
filemenu.add_command(label="Save", command=Curry(callback, "save"))
filemenu.add_command(label="Save as", command=Curry(callback, "saveas"))
filemenu.add_separator()
filemenu.add_command(label="Quit", command=root.destroy)  # better than root.quit (at least in IDLE)

menubar.add_cascade(label="File", menu=filemenu)

root.config(menu=menubar)

# create a toolbar with two buttons
# use Frame(root, borderwidth=2, relief='raised') for more separation
toolbar = Frame(root)

b1 = Button(toolbar, text="red", width=6, command=Curry(callback, "red"))
b1.pack(side=LEFT, padx=2, pady=2)
b2 = Button(toolbar, text="blue", width=6, command=Curry(callback, "blue"))
b2.pack(side=LEFT, padx=2, pady=2)

toolbar.pack(side=TOP, fill=X)

mainloop()
vegaseat
DaniWeb's Hypocrite
Moderator
5,989 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,417
 

thank u.. i appreciate ur helping nature.... thank u. i might need more help in the future too. about the GUI of Python, so help me . thank u.

katharnakh
Posting Whiz in Training
237 posts since Jan 2006
Reputation Points: 19
Solved Threads: 34
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You