I'm working on a PyGTK app with some Buttons that, when clicked, give a text entry dialog, then set the text on the button to whatever was entered in the box. The problem is that if the text is longer than the button can show, the button changes size to accomodate. How do I keep GTK Buttons from resizing when the text changes?
Have you tried set_size_request?
http://library.gnome.org/devel/pygtk/stable/class-gtkwidget.html#method-gtkwidget--set-size-request
button = gtk.Button("text on button")
button.set_size_request(width=30, height=20)
See:
http://www.pygtk.org/docs/pygtk/class-gtkwidget.html#method-gtkwidget--set-size-request
In glade, you can set "Width request" in the "Common" tab.
Related
I have a Python/Tkinter app with a bunch of Buttons and I want to give the user an ability to edit the text on these buttons.
The most intuitive approach to me is to create an Entry widget on top of the button if the user right-clicks the button, and temporarily hide the button.
I did that and it's somewhat working but there is a problem. The button does not want to stay hidden. E.g. I create an Entry widget and it initially appears on top of the Button. Then, if I click inside the entry box, it briefly disappears (for a second or two), showing the button again, and then reappears. If I hit 'tab' and move focus out of the Entry, it disappears completely (exposing the button again) and only reappears when I click back into the entry/button area.
Am I doing something wrong / unintended, is that a bug, and is there a workaround?
Here's my Entry creation code ('self' is the button widget):
def on_mouse_rightclick(self, event):
self.prev_state = self["state"]
self.entry = Entry(self, {"width":8})
self.entry.pack(side=TOP, anchor=W)
self.entry.insert(0, self['text'])
self.entry.bind('<Return>', self.on_entry_edit)
self.entry.bind('<Escape>', self.on_escape)
self['state'] = DISABLED
self.lower(self.entry)
I tried to call self.entry.lift() and even to unbind '<Button-1>' temporarily from the button widget, with no effect.
I'm using 32-bit Python 2.7.9 on Windows.
I'm making a text editor whose main widget is a Text widget for the user to actually enter text. I need to make the text widget fit to the window when the user resizes the pane. I kind of cheated by making the widget huge, but that's just a makeshift solution to let me work on other parts while I look for a solution. How can I make the Text widget automatically resize to fit the window?
Use pack to place the widget, with expand set to True and fill set to BOTH. Ex:
from tkinter import *
root=Tk()
text=Text(root)
text.pack(expand=True, fill=BOTH)
root.mainloop
I have a popup window with an entry widget using Tk, is there a way for the cursor to already be flashing when it pops up, so that the user doesn't have to click the entry widget to enter text?
You can use .focus()
widget_name.focus()
When a user selects a portion of text in a Tkinter Entry widget it becomes highlighted. However, when the user clicks away from the widget the highlighting disappears.
Is there any way to keep the selected text highlighted despite the Entry widget not having focus?
I'm attempting to make a custom right-click menu not based on the Tkinter Menu widget (it's based on a Tkinter Toplevel widget), and I would like the text to remain highlighted despite the menu having focus.
You want to set the exportselection option of the text widget to False
text_widget.configure(exportselection=False)
I have implemented an informational popup in a python app using a Tkinter Menu widget. I have a Text widget on a canvas in the root window. I created a Menu widget that has root as its parent. When I detect a mouse hover over the text widget I post the popup menu with menuWidget.post(). When I get a leave event from the text widget my intention was to have the popup disappear by calling menuWidget.unpost(), only the popup menu does not disappear until I click elsewhere outside the text widget.
First, is this a sane method for implementing an informational popup? And can anyone tell me why the popup menu won't disappear?
This is not the right way to do an informational popup. On the Mac and on windows machines menus are native controls. Because of this the unpost command doesn't work because tk cedes control to the system event loop in order to get platform-specific behavior.
What you want is to use instead is a toplevel window with the overrideredirect flag set. This lets you display a borderless window anywhere you want. The upside to this is that you aren't limited to simple text -- you can put anything you want in that toplevel -- another text widget, a canvas, buttons, etc.