How to plan tkinter GUI in Python - python

I am writing a simple menu-based RPG (combat is turn-based and such), but I have realized I had better organize all of my widgets before I actually start implementing the GUI. My application "changes windows" by lifting frames containing widgets or other frames (or both). Is there a commonly-used or suggested method or organization program to help me keep track of everything neatly before I start?
Thanks.

If you want to say do health as a number like 0/1 then you could do this line of code for a label.
new_label = tkinter.Label(window, text="Health: %s/%s" % current_health, max_health,bg="green")
new_label.pack(side=tkinter.LEFT)
that would assign variables to your label for may health and current health and display it on the left of your screen. Also it will have a green background ofr the label but that can be changed. Really that is basic gui in a tkinter application hope this helped.

Related

Making a game overlay in python

So I am trying to make a python script that when I do a certain hotkey combination, It shows a text box as an overlay like what "Geforce Experience" and "Windows Gamebar" do.
the problem is that in the game when I interact with the text-area loses focus and goes minimized as opposed to the 2 programs I spoke about before, for example windows game bar allows you interact with a lot of options while the game is still on foreground and you close the bar you are left with whatever you were with before...
I'm using tkinter for now, and if there are solution not including tkinter it is Ok as long as it achives the goal.
As far as I understand what you are trying to do is create a overlay for a game and the overlay should be created using tkinter object. Here is a library that can do that, however as far as I remember you needed to change something in it's python file, however this might have already been fixed.

I want to add a scrollbar to the screen of my app but I'm using grid instead of pack and I don't want to use a canvas. I'm a beginner by the way

Iv'e tried a bunch of random things. I know I'm supposed to be specific when explaining this but I don't really know what to say. I made a scrollbar in a def function, it was in a whole new screen and I added it to a text box. So I'm wondering if I can just add my main scrollbar to the frame/screen in my main window. My previous scrollbar is in the recipe_steps function.

Unable to make a desktop like container in Python Tkinter

I need to make a desktop container kind of frame in Python so that from the menu bar I choose the option the window would open in that desktop pane, Like we use to deal with the Professional Applications.
Here is the Snapshot of the GUI. In the Snapshot the above Menu bar has lots of cascaded options as well. As the User choose the cascaded option, a new window should open below the Menu bar (Empty space in snap), and when the other option is chosen the previous frame should also be there and these sub frames should also have close,minimize and maximize button (e.g. Minimize Minimizes to the bottom of the frame space above the status bar
You are trying to create what is commonly referred to as a "Multiple Document Interface", or MDI. This was popular back in the 80's and early 90's, but is now generally considered to provide very poor usability.
Tkinter does not natively support MDI applications. You will have to do all the window management yourself. Generally this means that you'll use a canvas for the containing window, and then embed frames within the canvas to represent your windows. You'll have to draw your own window borders and handle resizing. I've seen it done, but it's usually not worth the effort to implement.

tkinter: Is it possible to attach GUIs from different tkinter programs together and easily navigate across them?

I'd like to build a number of tkinter GUI apps and then stack them together either horizontally or vertically. I'd also like to navigate across the app easily once they become attached so that at any time I can focus on them.
One idea in my mind is that I can have a webpage like frame container, with a scrollbar, then drag other app's GUIs into it so that I can scroll across them.
To attach the windows, I understand that maybe I can get individual app's window through process info, but I just want to make sure if there is a built-in or better way of doing the things I want.
Seeing as you didn't capitalize tkinter, I'm going to assume that you are working in Python 3. If this is so, there are two options that I can think of: Using tkinter frames/grid geometry manager to place each widget side by side, and using tkinter.ttk Notebook to have multiple application tabs. you could also mess around with creating a scrollable tkinter Frame if you were dead set on the scrolling part, but from other Stackoverflow pages it appears that there is no native way to do that.
Example of tkinter.ttk Notebook

Python + Qt -> 2D overlay over other full screen app?

Backgroud:
I play Grand Strategy Games a lot. Part of addcition comes out of AARs (After Action Reports). Stories players write about games. Ofc. that require save games cause "quick" game is longer than 10 hours.
Problem:
Game do not support automatic save games other than 3 autosaves that get overridden every time. So I want to write app that will use Qt for tracking file changes. Every time game auto saves, this app will rename and move to choosen location savegame.
But since its full screen game, players may forgot to turn on my app I need way to indicate state of my app.
Question:
How can I make 2D overlay over portion of full screen 3D app, given that I use Python and Qt?
Alternative
I do not think that sound warnings would solve my problem, since it would work if someone forgotten to choose save game to track, but it would not work if someone completely forgot to turn on my app. While lack of icon would be enough to inform about such mistake.
But if you can find any other way to indicate that my app is not turned on or configured, post your ideas in answers.
Very old post, but I will let this reply here for others looking for something similar.
Check PyWinCtl. If you are able to build a frameless, semi-transparent window using Python and Qt, alwaysOnTop(True) and acceptInput(False) methods will make the trick, but only with games based on CGI calls, not if they use DirectDraw Exclusive Mode (for this, I'm also searching for a Python solution, this is why I ended here!)
In the meantime, you can try this on Qt when initializing your window (it's a piece of code, not reproduceble, sorry):
# Make it transparent to input
self.setFocusPolicy(QtCore.Qt.NoFocus)
if "Linux" in platform.platform():
self.setAttribute(QtCore.Qt.WA_X11DoNotAcceptFocus, True)
self.setAttribute(QtCore.Qt.WA_TransparentForMouseEvents, True)
self.setAttribute(QtCore.Qt.WA_InputMethodTransparent, True)
self.setAttribute(QtCore.Qt.WA_ShowWithoutActivating, True)
# Make it semi-transparent
self.setWindowOpacity(128)
# Setting flags: on top, frameless and no focus
self.setWindowFlags(QtCore.Qt.Tool| QtCore.Qt.CustomizeWindowHint | QtCore.Qt.WindowStaysOnTopHint | QtCore.Qt.FramelessWindowHint | QtCore.Qt.WindowDoesNotAcceptFocus)
I think the name of the functions and parameters are self-explicative (let me know if they are not).
The part of making your window transparent to input methods is important, otherwise the window can be eventually clicked and the game will lose focus. This effect on the window is permanent.
The part of making your window semi-transparent will not work as is. You need to implement a custom paintEvent for your window, like this (again, not reproducible, sorry):
def paintEvent(self, event=None):
# This is required to draw a semi-transparent window
# https://stackoverflow.com/questions/33982167/pyqt5-create-semi-transparent-window-with-non-transparent-children
painter = QtGui.QPainter(self)
painter.setOpacity(0.4) # or your desired opacity level
painter.setBrush(QtCore.Qt.black) # or your desired background color
painter.setPen(QtGui.QPenQtCore.Qt.black)) # or your desired background color
painter.drawRect(self.rect())
The part of making it always on top might not be permanent, this is why using pywinctl's alwaysOnTop() is recommended, furthermore, it's better to recall it, for instance every second, to bring your window back to top in case it's obscured by any reason.

Categories

Resources