I have created a UI that can be launched inside Maya. My class for this window inherits from QDialog. I want to have a button that will open a jpg into a new window, and then it closes with another button. While this other window is open I would like to still be able to interact with the main window. Is it possible to do this? How would I go about launching this new window?
You can use this code to get what you want. I tested it in Maya 2016.5 on macOS. Works fine!
import maya.cmds as cmds
def loadSecondWindow(*args):
window = cmds.window()
cmds.paneLayout()
cmds.image(image='/Users/swift/Desktop/scientist01.jpg')
cmds.showWindow(window)
def deleteSecondWindow(*args):
if (cmds.window('window2', exists=True)):
cmds.deleteUI('window2')
cmds.window(width=200)
cmds.columnLayout(adjustableColumn=True)
cmds.button(label='Window with Picture', command=loadSecondWindow)
cmds.button(label='Delete Window', command=deleteSecondWindow)
cmds.showWindow()
Related
I´ve built a simple GUI app, and I´m playing with pystray.
Actually, my script starts as usual, the first thing you see is the GUI.
If you klick on exit, the GUI minimize, and the tray Icon spawns.
For now, i search a way to start my script in this "tray Mode"
here are some informations:
class Hauptfenster:
# Define a function for quit the window
def quit_window(icon, item):
icon.stop()
fenster.destroy()
# Define a function to show the window again
def show_window(icon, item):
icon.stop()
fenster.after(0, fenster.deiconify())
# Hide the window and show on the system taskbar
#staticmethod
def hide_window():
fenster.withdraw()
image = Image.open(os.path.join(application_path, iconFile))
menu = (item('Beenden', Frontend.Hauptfenster.quit_window), item('Einstellungen', Frontend.Hauptfenster.show_window))
icon = pystray.Icon("name", image, "Quicksafe", menu)
icon.run()
Please ask me if you need some more Information and Thanks a lot !
Best regards
Background:
My programm should lay in the autostart of win10 , but i dont want to minimize the window each time i restart my pc
I just added my method hide_window to my main function,
when script starts, you see something moving on to screen for 2ms.. but it disapears very quick... so thats something I can live with
I'm new using tkinter on python and I would like to develop a program that can Drag and Drop a button pressing other one... I will try to explain : I have button 'A' that will create a new button 'B' and I want to Drag the New button to another place
Any help
Thanks
The tkinter.dnd module, as suggested by j_4321 in comments.
Here is some sample code using that library to do what you have said:
from tkinter import *
from tkinter.dnd import Tester as DragWindow, Icon as Dragable
# Make a root window and hide it, since we don't need it.
root = Tk()
root.withdraw()
# Make the actual main window, which can have dragable objects on.
main = DragWindow(root)
def make_btn():
"""Make a new test button."""
# The functional part of the main window is the canvas.
Dragable('B').attach(main.canvas)
# Make a button and bind it to our button creating function.
Button(main.top, text='A', command=make_btn).pack()
# Start the mainloop.
mainloop()
I am having a problem with getting tkSimpleDialog to take focus over my fullscreen window GUI. I have a GUI that I am trying to use a dialog window to use as an admin password to close the GUI (like a kiosk mode app) using root.quit(). The problems with this are that the dialog does not come in front of the parent windows if the parent windows are fullscreen. Additionally, I would like to make the tkSimpleDialog go fullscreen as well.
Here is the code for how the dialog box is being called/created using the tkSimpleDialog.py in my program:
def check_admin_password():
# use askstring here to verify password.
pass_attempt = simpledialog.askstring("Verifying access","Please enter Admin password", parent=window, show="*")
if pass_attempt == "password":
root.quit() # used whatever your instance of Tk() is here in place of root.
admin_minimize_button = Button(window, text = "Administrator", command = check_admin_password, width=35, height=12)
admin_minimize_button.grid(row=4, column=0)
I am using the following code for the parent window and I believe there is something with the overrideredirect(True) that is affecting the focus of my dialog window:
qwindow = Toplevel(root) #renames Toplevel "popup" window frame to variable "qwindow"
qwindow.title('Mission Queue') #creates title on popup window
w, h = qwindow.winfo_screenwidth(), qwindow.winfo_screenheight() #aquires dimensions from display size
qwindow.geometry("%dx%d+0+0" % (w, h)) #sets window size to aquired dimensions
qwindow.overrideredirect(True) #removes top bar and exit button from parent window frame
I have tried editing the tkSimpleDialog.py file and adding an overrideredirect(True) line however that is not working. If more information is needed, let me know. Any advice would be much appreciated. Thanks in advance.
Due to my inability to figure out a solution using tkSimpleDialog, I attempted a different approach creating my own "dialog". Unfortunately, I was still unable to get the dialog to have the entry line take focus with the screen window being set to wm_attributes('-fullscreen', 'True') and overrideredirect(True). While it would have been better to have both work; for my purposes, it will work fine to just be fullscreen in my application without overrideredirect(True). For anyone with a similar issue or wanting to see more documentation on my progress, heres the link to my other forum post: (Tkinter Entry Widget with Overrideredirect and Fullscreen).
Thanks for the help!
Ive been trying to do this for a while now, but haven't figured out a way to do it.
I have a tkinter script, that creates a popup window when a button is pressed. However I don't want the user to be able to click away from this window to any previous windows created. I have got this working with root.grab_set(), however there is no indication to the user that they must stay on that window.
class popup(object):
def __init__(self, parent):
self.root=Toplevel(parent)
self.root.grab_set() #prevents the user clicking on the parent window
#But the window doesnt 'flash' when an attempt to click away is made
For example, when you have a window created by the filedialogue module, if you attempt to click onto another window the filedialogue window stays on top and has a 'flashing' animation to let the user know they cant click away. Is there a way I can reproduce this effect? Going through the source of filedialogue hasn't been fruitful for me, and neither have Google searches.
The simplest way i can think to do this is to use an event and the focus commands, along with the windows bell command:
#!python3
import tkinter as tk
class popup(object):
def __init__(self, parent):
self.root=tk.Toplevel(parent)
self.root.title("Popup")
self.root.bind("<FocusOut>", self.Alarm)
def Alarm(self, event):
self.root.focus_force()
self.root.bell()
main = tk.Tk()
main.title("Main")
pop = popup(main)
main.mainloop()
Here's a solution for Windows that uses FlashWindowEx from the user32 dll. You need to pass a FLASHWINFO object to it. The grab_set makes sure the popup window stays in focus and disables any widgets in the main window, making the popup transient makes sure it's always on top of the master. The <Button-1> event is used to check mouse clicks, and winfo_containing checks if another window than the popup is clicked. I then set the focus back to the popup and flash the window in focus (which then always is the popup).
You need pywin32 to use this.
import Tkinter as tk
from ctypes import *
import win32con
class popup(object):
def __init__(self, parent):
self.parent = parent
self.root=tk.Toplevel(self.parent)
self.root.title("Popup")
self.root.grab_set()
self.root.transient(self.parent)
self.root.bind("<Button-1>", self.flash)
def flash(self, event):
if self.root.winfo_containing(event.x_root, event.y_root)!=self.root:
self.root.focus_set()
number_of_flashes = 5
flash_time = 80
info = FLASHWINFO(0,
windll.user32.GetForegroundWindow(),
win32con.FLASHW_ALL,
number_of_flashes,
flash_time)
info.cbSize = sizeof(info)
windll.user32.FlashWindowEx(byref(info))
class FLASHWINFO(Structure):
_fields_ = [('cbSize', c_uint),
('hwnd', c_uint),
('dwFlags', c_uint),
('uCount', c_uint),
('dwTimeout', c_uint)]
main = tk.Tk()
main.title("Main")
pop = popup(main)
main.mainloop()
As it is now, the flash only occurs when the main window's body is clicked, so clicking the title bar just returns the focus to the popup without flashing. To make it fire also when that happens you could try using the <FocusOut> event, but you would have to make sure it only happens when the focus passes to the main window, but it never really does since the grab_set is used. You might want to figure that out, but as it is now it works quite well. So it's not perfect, but I hope it helps.
First of all, this issue is only happened in WIN7, and it is normally under raspberry pi (Debian Linux).
I have two window, the main window and a child window. The main window has a button which can activate the child window. The child window has a text entry box which can input the strings. The issue is when activate the child window at 1st time, the text entry box is functional. But when the child window is closed and re-opened, the text entry box seems disabled that cannot input any text into it, even set_text("xx") function cannot write any text into it.
The detailed steps are:
run the py script
click the button on main window to open the child window. I have tried with the below three methods, it seems they have same issue:
def on_button_clicked(self, widget, data=None):
self.child_window.present()
#self.child_window.show()
#self.child_window.show_all()
Now the child window is opened and the text entry box is functional, I can type any text into it.
Close the child window. I have bind the delete signal on to the child window. So every time the child window is closed, the below function will be executed, which will hide the current child window.
def on_WindowOfScanning_delete_event(self, widget, data=None):
self.child_window.hide()
return True
Now the main window is on focus and click the button to activate the child window again.
self.child_window.present()
Now the child window is appear, but the text entry box seems disabled.
Any one can help me on this issue? Appreciated for that..
The version information is: Python 2.7.3 GTK 2.24.2, and I use glade to manage the GUI interface.
================= The same question with a different example: =====================
http://www.pygtk.org/pygtk2tutorial/sec-TextEntries.html#entryfig
This link is the pygtk's official example. While running on my WIN7(64bit) system, the text entry box cannot be edited since the first time opening. But if you move mouse to activate other window, and turn back to this gtk window, the text entry box can be edited then. I am not sure if this is a pygtk's bug.
I have tried python 2.6.6 and 2.7.3 with pygtk2.24.2-all-in-one.
================= The solution to this issue: =====================
It seems no one have such kind of problem so I post my own solution.
1st, give up using the window.hide() function.
2nd, destroy the child window every time it finished its job, and re-init the gtk.Window again to invoke the child window. Here is a simple example:
#!/usr/bin/env python
import pygtk
pygtk.require( "2.0" )
import gtk
class PopupExample(gtk.Window):
def __init__( self ):
gtk.Window.__init__(self)
self.connect("destroy", lambda *w: gtk.main_quit())
button = gtk.Button("Popup Window")
button.connect("clicked", self.show_popup_window)
self.add(button)
def show_popup_window(self, button):
popup = gtk.Window()
popup.add(gtk.Entry())
popup.show_all()
if __name__ == "__main__":
pe = PopupExample()
pe.show_all()
gtk.main()
I encountered the same problem in gnucash and inkscape,
I solved this problem by going into Control Panel -> Locales and Languages and set format to English(US)