I have this program that stores some information about my books, and this information is shown in windows, that appear whenever I double-click a book title in a list. But there is the possibility of searching for a book using it's title or author, and that can make the program open multiple windows. My problem is, all the windows are opened one over the other, and, until the I move a window, or close it, it seems that only one window was opened. Is it possible to, with python and tkinter, make the windows appear in slightly different positions?
You can use the geometry method of a window to specify where you want it to appear. For example, w.geometry("+100+200") will open the window w at coordinate 100,200. Each time you open a new window, adjust the coordinates appropriately.
Normally, though, this is something the window manager does for you. It's odd that it's not doing this for you.
The geometry method is documented here, among other places: http://effbot.org/tkinterbook/wm.htm#Tkinter.Wm.geometry-method
Related
How can I can a function and create a function for the icon context menu? I want to make the iconic Open New Window function pop-up when you right click on the icon menu in the taskbar/dock. See this question for more info on this kind of question.
Places I have looked but found nothing:
https://www.tcl.tk/man/tcl8.5/TkCmd/tk_mac.html#M15
https://pyinstaller.org/en/stable/feature-notes.html#open-event-handling-in-a-tkinter-based-gui-application
While there are a tiny subset of apple events that you can benefit from the DockMenu is not accessible directly via tkinter. Turns out mac is not really open for modifications and even smaller tasks can be hard. You could consider to use a system tray icon instead.
So there is probably a real basic solution for this but I obviously don't know what it is. When I'm writing code in IDLE window, eventually I get to the bottom of the window and then each new line of code I write is at the bottom of the window, which is annoying to read as I'm continually staring at the bottom of my screen as I write each new line of code. Is there a way to get the IDLE shell to jump back to the top of the window once I reach the bottom?
Or another way to look at it would be to constantly have roughly 20 or so empty lines present after the new line of code I'm writing, so that my code never gets to the bottom of the window and thus each new line of code I write is always centered in the window.
I know I could simply minimize the window itself and position it so that the bottom of the window is in the center of my screen (vertically) but that's not really a solution as then I'm dealing with this window sliver that I'll have to maximize every time I want to review my code in it's whole.
Thanks!
The behavior of IDLE's Shell intentionally mimic the behavior interactive Python in command-line console and terminal programs. The latter typically default to 24 lines because that is what physical glass terminals usually had. On modern high-definition monitors, 'normal' size fonts allow more lines on a screen. If a 24-line window is put with its top at the top of the screen, the bottom line is at the middle of the screen.
IDLE defaults to 4O so one can seen more text at one time. You could customize this to fewer lines, but this would reduce the side of editor windows also. You could instead resize just the Shell with your mouse, and then move it up to the top of the screen. When you want to see more, you can use Zoom Height on the options menu. If you do not like the default hot key you can change it.
When Shell starts, there is a blank space beneath the input prompt. This space is not filled with blank lines. If it were, you could move he cursor down. Once the window is filled with lines of whatever length, the only way to restore the blank space is to delete all but the last N lines. https://bugs.python.org/issue6143 is about clearing all or possibly just some of the shell output.
PS. The Shell windows uses one tkinter Text widget for both read-only history and read-write code entry. I have thought about using two text boxes instead. This might allow keeping entry permanently above the output instead of below, but it is not clear if you would like this any better.
If I were to do make this split, I might add a configurable minimum size for the entry box, so that entry would always start k lines above the bottom. But this is speculative and still in the design stage.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
I would like to position the icons on my taskbar windows 10 in the center of the desktop.
I know the famous TaskbarX does it but I don't know how to do it in python, could someone explain to me or give me the path in the registry to modify please
Example of center icons taskbar
On Windows 10, you can't center icons just by modifying the Windows Registry.
But on Windows 11 you just modify TaskbarAl (0 = left, 1 = centered) value in \HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced.
What TaskbarX and other similar tools do for Windows 10 and prior versions, is to calculate the taskbar icons location using accessibility functions like UIAutomation or MSAA.
As shown in the picture above, using UI Accessibility Checker tool by Microsoft, this is showing the MSAA tree of the explorer.exe process, specially that instance that holds the taskbar.
First, find the taskbars instances, using EnumWindows and pick those beloging to explorer.exe process that has as Win Class Name "Shell_TrayWnd" (for primary monitor) and "Shell_SecondaryTrayWnd" (for the other monitors). Once you found them, using that tool as a guide, find the exact running applications list in that accessibility tree, for each taskbar instance (main monitor and secondary monitors). Once found the exact location of the taskbar list icons, pick the first one's left position and then the last one's right position. With that coordinates you will get its real width inside taskbar window, and using SetWindowPos modify its position in its taskbar area using its child windows container.
In the previous picture, you can see the hierarchy of child Windows inside the main taskbar's Shell_TrayWnd window handle, the child that contains the running applications is named ReBarWindow32 which has its own coordinates within that taskbar window, you just modify it using a timer or a shell event whenever a new process is started, or existing one is closed, or switched to another virtual desktop, and maybe other events, all that in order to re-adjust its location (centering in your case).
Normally, using timers will be polling the system unnecessarily, it is recommended to use the shell messages that Windows taskbar itself relies on, as mentioned here https://devblogs.microsoft.com/oldnewthing/20201228-00/?p=104610 you register your process as a shell message client or hook the shell message https://learn.microsoft.com/en-us/windows/win32/winmsg/about-hooks, that depends on you.
You can take a look a PowerToys source code, specially the module ShortCutGuide, that shows the taskbar's icon location with numbers. https://github.com/microsoft/PowerToys/blob/master/src/modules/ShortcutGuide/ShortcutGuide/tasklist_positions.cpp just find a way to port it to Python and proceed as mentioned above.
I repeat, Windows 10, doesn't offer that centering functionality out of the box unlike Windows 11.
If you see the last picture, that snapshot belongs to a child window hierarchy in Windows 11's taskbar, but if you'll compare to your Windows 10, 7, 8, etc. (using UUSpy tool or Spy++) you will notice that this picture shows extra child windows, specially using Xaml string in its class names. Those are new children that now holds not only the task list, but the Start menu button, search, widget, etc. they're not found in Windows 10 or previous versions. However, Windows 11 still keeps the older list child window "ReBarWindow32" (that one used in previous Windows versions) but it is hidden in favor of the new ones, and I guess they will remove it in the future, since this new one does the centering and animations when new apps are launched or closed, etc.
I am trying to know if there is a approach in python to read the tabs on the taskbar and get the list of them.
Suppose I have a task bar which has outlook,word,Skype minimized. I would like my code to get the list of things which are on taskbar.
Example:
Here if you notice outlook,slack,chrome,skype and notepad is open. So
what is the approach I need to follow to tell my code to return the
list of open things on taskbar.
My problem is when somebody runs my tkinter gui (in Windows 7) and has larger display settings (125%), the gui doesn't look well (buttons are closer to each other, end of text cannot be seen, etc.). I use place method with x - y coordinates to place the widgets.
Maybe using pack method could solve this, but it is easier to use place for me, because there are lots of labels and buttons with exact places.
Another solution can be if the display settings could be checked with pywin32 and resize everything if needed. If it is possible, please confirm and help, what is the related function or if you have any other idea/advice, please share it.
This is one of the reasons why place is a poor choice. You should switch to using grid and/or pack. They are specifically designed to handle different screen sizes, different resolutions, different widget styles, and different fonts.