I'm using Python 2.7.4 with Gtk3 on Ubuntu 13.10.
I'm using the Keybinder library to hide and show my Gtk window using a hotkey. Now, when my window does show up using the hotkey, it does not always receive focus.
The concerned code is below:
def toggle(self, key, data):
if self.hidden:
self.hidden = False
self.set_keep_above(True)
self.set_accept_focus(True)
self.present()
self.enteredName.grab_focus()
else:
self.hidden = True
self.hide()
Here, self refers to the Gtk window and self.enteredName is a widget of type Gtk.Entry().
Normally, the combination of set_accept_focus(), set_keep_above(), followed by present() works. Without the set_keep_above, my window doesn't rise to the top. Without the set_accept_focus, my window doesn't get keyboard focus.
The above set up works when I just start my app and then test it using the hotkey (hiding and showing it). My window always receives keyboard focus. Howver, let's say I have a GVim window opened and I've given keyboard focus to it. On pressing the hotkey, my window shows up on the top (even on top of the GVim window), but the keyboard focus still lies with the GVim window.
I've tried several combinations (by adding activate), and grabbing focus on a text widget. But it's not working as expected.
Anything I'm missing here?
Related
I am trying to write a program that allows the user to press different buttons in a full screen Tkinter GUI. The operations these buttons preform does not matter for my question, but I am having trouble creating a popup dialogue (askokcancel) to confirm that the user wants to press a button, then run the rest of that buttons code normally if "ok" is pressed. Currently, I have this program running from boot through the /etc/profile file, accessed via
sudo nano /etc/profile
Here I change the directory to the folder containing my python file and have it load my code, and upon booting up it loads my buttons correctly and upon pressing the correct button the popup window appears over the full screen window. However, when I try to run my code through the desktop shell, upon pressing the button, the popup window DOES appear, but is hidden behind the root window. I am not able to click anywhere else, and pressing "tab" and "enter" allows me to navigate between the two choices and pick one, but without being able to see it. I have buttons printing words in the shell, so I know the popup window is actually there.
The full screen makes use of the overrideredirect function, hiding the task bar and other options. When this is set to FALSE, the popup works as intended, but I am trying to make the GUI be the only thing on the screen.
Here is a condensed version of my code:
from Tkinter import*
import tkMessageBox
class Application(Frame):
def run(self):
tkMessageBox.askokcancel("Run Confirmation!", "Are you sure?")
print "RUN Code Intitates"
def createWidgets(self):
self.button1 = Button(self,height=15,width=20)
self.button1["command"] = self.run
self.button1.pack({"side": "left"})
def __init__(self, master=None):
Frame.__init__(self, master)
self.pack()
self.createWidgets()
root = Tk()
w, h = root.winfo_screenwidth(), root.winfo_screenheight()
root.overrideredirect(1)
root.geometry("%dx%d+0+0" % (800, 480))
app = Application(master=root)
app.mainloop()
root.destroy()
I am by no means a computer science major and have only been working with raspberry pi, tkinter, and python for a couple weeks, so if I am missing something basic I apologize. I am using an 8" touchscreen display made for raspberry pi as my screen.
According to the tcl/tk documentation:
Setting the override-redirect flag for a window causes it to be
ignored by the window manager; among other things, this means that the
window will not be reparented from the root window into a decorative
frame and the user will not be able to manipulate the window using the
normal window manager mechanisms
So the window does not always behave has expected (it is less the case in Windows). For instance, in Linux, the window does not get keyboard focus (python tkinter overrideredirect; cannot receive keystrokes (Linux)).
If what you really care about is to have a fullscreen GUI, just replace
root.overrideredirect(1)
by
root.attributes('-fullscreen', True)
and the window will behave normally so the message box will appear on top of the main window.
Another possibility in Linux is to replace
root.overrideredirect(1)
by
root.attributes('-type', 'dock')
This tells the window manager to treat the window as a dock, and at least in XFCE, it results in a window with no decorations, always on top of the other windows, but the message box does appear on top of it.
Is it possible to capture a screenshot of a wxpython GUI program when the program menu on the menu bar drops down?. I attempted to do this by pressing the print screen key on my keyboard but it didn't work.
Nevertheless, the print screen function key works fine when the menu on the menubar does NOT drop down.
I noticed I can take screenshots of other GUI programs on my system when their menu options are seen .
If this is possible, what codes can I place in my program to facilitate a successful screenshot when any menu is showing?
I just tried "Shift-prt scr" on my Windows 8.1 to capture a screen with a menu shown (used the wxPython demo) and it worked for me.
You can also use a screen capture utility, e.g. I often use IrfanView, to do this, with it I set a timer to capture things which go away when the window looses focus.
With Ubuntu using Mate under Applications--> Accessories there is a Take Screen shot option.
The actual command is mate-screenshot --interactive
this allows you Full screen, Current window or Selected area, with a "Grab delay", I found it particularly useful documenting wxpython, although you will have to drag the window to a size to accommodate the full menu or you end up with it cut off.
Note: gnome-screenshot --interactive, is another alternative.
Edit:
Have you checked out pyscreenshot?
https://pypi.python.org/pypi/pyscreenshot
It claims the following usage:
Example:
import pyscreenshot as ImageGrab
# fullscreen
im=ImageGrab.grab()
im.show()
# part of the screen
im=ImageGrab.grab(bbox=(10,10,510,510)) # X1,Y1,X2,Y2
im.show()
I want to make a click through window. A window which I click but the click pass to the window below it.
I've found this two solutions for windows:
How to make click-through windows PyQt
I have a form that can "click through", i.e. direct clicks to the window below. How can I undo my changes after the event?
But I want it to work in linux. I study the xlib mechanisms but cannot understand how the window stack works. Actually I can get all the windows with XQueryTree() and found the ones under my window. But I don't know witch one are above.
im having some problems to send to the front a GTK window.
I have a main window (window_root) with a button that launches another window (window_programs).
with this commands:
window_root.hide()
window_programs.show()
then, in window_programs, i have a button that displays another window (window_list) with the command:
window_list.show()
window_list is modal.
The problem was that window_list appeared at the back of window_programs.
so i did some research and i found window_list.show().
The problems is that window_list appears at the front, but when i click it window_programs comes to the front!
it makes some time that i'm looking for the solution, any help will be appreciated!
You are looking for the transient-for property of the modal window (which should be available in Glade). If the modal window needs to be transient to either of the two other windows, then you need to use gtk_window_set_transient_for() as needed since the modal can only be transient for one window at a time.
Is there any way to get a border like this in Tkinter? Notice how it lacks the buttons on the top right. Also I don't want this program to show in the task bar.
This is in windows 7, btw.
Tk (and thus, Tkinter) has a command for removing all window manager decoration. This command in tkinter is the "wm_overrideredirect" method of toplevel windows. Pass it a parameter of True to remove the window manager decorations. You can then draw whatever borders you want, usually by packing a canvas over the entire window and drawing on the canvas.
However, when I experiment with this on my Mac, the window appears properly but won't take focus. Perhaps this is a bug in Tkinter. I don't see the same problem with identical code in Tcl.
The WS_DLGFRAME window style should give you a window without a titlebar and WS_EX_TOOLWINDOW is normally also used for a window like this so it is not visible in the taskbar (Or with a hidden parent window like control panel dialogs before Vista) You can figure out the exact window styles with a tool like Spy++ (Visual Studio) or WinSpy++