---- * '''Back''' to.....................: [Answered Questions On: Basic Tcl] * '''Forward/Home''' to the: [Answered Questions Index Page] * Ask '''New Questions''' at: [Ask, and it shall be given.] ---- Oct 11, 2004 Hi, Does anyone know hot to enable/disable parts of a GUI being created in tk, based on user input on the same screen. What I mean is, I have all the frames created in a single window, and want to enable some frames as and when a user requires that option. For example, I have an option menu (tk_optionMenu) with 2 values, asking the user if he wants random numbers to be used. If he does, then I want the frame with the options of the type of random numbers to be enabled, otherwise, I want it to be disabled. Pls help. I cant seem to find anyway of doing this. Thanks GPS Oct 11 2004 - [MG] You can watch the variable assigned to the tk_optionMenu via trace, and enable/disable your GUI when it changes. For instance... pack [frame .l] -side left pack [label .l.l -text "Random number?"] -side left pack [tk_optionMenu .l.m ranNum "Yes" "No"] -side left proc enableGUI {{args ""}} { global ranNum if { $ranNum == "Yes" } { # $gui configure -state normal } else { # $gui configure -state disabled } };# enableGUI trace add variable ranNum write enableGUI Oct 12 2004 - Thanks alot MG. This piece of code is exactly what I needed. GPS ---------------- 2004/09/21 pcor Platform: Mandrake Linux 9.2 Interpretor: tixwish8.1.8.4 I have been trying to use a canvasprintdialog to print a canvas embedded in a Toplevel window but whenever the canvasprintdialog is positioned in front of the canvas I get the dialog in the printout. How can I exclude the dialog without having to position it elsewhere on the screen. I have tried hiding the dialog and using tkwait before issuing the "print" command but so far to no avail. Any help will be much appreciated. Thanks. Peter Newman 21 September 2004: I haven't tested it, but surely:- ...hide the dialog ---or--- `raise canvasToplevel' ... update ...print the canvas... would work. pcor: Thanks Peter. Yes it does. Being a newbie with Tcl I didn't know about update. ---- '''QUICK AND EASY BALLOON HELP''' Florian Boesch 25 June 2004: The Menu widget can be used to make popup menues. What widget can be used to make small popup ( tooltip style ) text messages? And what about popup selection-lists? Peter Newman 25 June 2004: Most Tcl'ers seem to refer to those pop-up help widgets as "balloon help". There are just over 3 zillion such widget packages available. Search for "balloon help" on the Wiki. But the ones I've tried were all way too complicated and unreliable. People seem to put zillions of binding on them, and Tk very quickly gets confused. Try some of the others. But you might be better off to roll your own. It's only about 10 lines of code. Something like (off the top of my head):- proc PopupHelp_forThisButton { } { toplevel .myPopup ; wm overrideredirect .myPopup (Gets rid of the Border) frame .myPopup.onePixelBlackBorder -background Black -borderwidth 1 label .myPopup.onePixelBlackBorder.text -background LightYellow -text {Blah blah blah} } Bind it so that mouse entry/exit to the button/widget you want the help for, pops up the help box, with:- bind .thisButton PopupHelp_forThisButton bind .thisButton {destroy .myPopup} And you'll need to position it near whatever it gives help for with winfo, etc. Sorry it's a bit crude & incomplete. But hopefully gives you the idea. Popup selection boxes are the same. But just use a listbox instead of a label. Florian Boesch 25 June 2004: Thank you! This gives me a good idea how to go about it. I may translate a little. from Tkinter import * def coords( geometry ): return map( int, geometry.split( '+' )[1:] ) class baloon( Toplevel ): def __init__( self, text ): Toplevel.__init__( self ) Wm.overrideredirect( self, 1 ) self.border = Frame( self, background='black', borderwidth=1 ) self.border.text = Label( self.border, text=text ) self.border.text.pack() self.border.pack() def set_pos( self, x, y ): Wm.geometry( self, '+%s+%s'%(x,y) ) def show( self ): pass def hide( self ): pass class application( Tk ): def update_baloon( self, event ): x, y = coords( Wm.geometry( self ) ) self.baloon.set_pos( event.x+x, event.y+y ) def __init__( self ): Tk.__init__( self ) self.frame = Frame( self, width=512, height=512 ) self.frame.pack() self.bind("", self.update_baloon) self.baloon = baloon( 'blahblubber' ) app = application() app.mainloop() This works for me. Now what I intend to do is to use this baloons to give hints about marks in my text, given that the position of a mark in the text lies within the windows borders and the user has choosen to show the baloons ( on a sidenote, can I make toplevel windows transparent? ). Also I have aproblem with this since on windows the baloon is spawned behind the main window, how to resolve this? Peter Newman 26 June 2004: To position the balloon over the main toplevel, make the balloon toplevel a child of the main toplevel. Ie:- toplevel .myMainToplevel ... toplevel .myMainToplevel.balloonHelp Alternatively, use the raise command. As regards toplevel transparency, see Transparent Toplevel. But that technique's not really a good solution. On Windows (95 to XP inclusive) however, transparent toplevels are a piece of cake. See the absolutely brilliant "Win32 Window Skinning" tutorial by Vander Nunes at [4]. Access the Win32 API with eg; Ffidl, critcl or SWIG. An alternative to the toplevel method of creating balloon help, is to simply place the label (or text or html or canvas) widget containing your help text in the same place you'd pop-up the toplevel. It's faster and simpler to code than the toplevel - and better still is linked to the parent widget it's been placed in/over. In other words, if you move or minimise etc your text widget, the help popup does the same with it. And since you can place more than one widget anywhere you like over your main widget, your help pop-up is effectively a transparent toplevel.