Tkinter - place_forget command - python

If I have used the place_forget command in order to hide a button when switching frames, how can I bring the button back at a later stage in the program? Or would I have to recreate it?

You will need to call place again. You do not have to recreate the widget as long as you keep a reference to the original widget.

Related

The proper way to display multiple windows in tkinter?

I am currently working on a project using Python and tkinter.
The problem is that I don't know what's the proper way to display multiple windows, or screens, I don't know how to call them. Let me explain better.
When the application starts the login screen appears. After that, if I click register, I want to go to the register screen, but I don't want it to be a separate window (I don't want to have 2 windows displayed at the same time), but rather another window with different content ?!
How should I handle properly this situation? Create a second window using Toplevel and hiding the first (can I do that?) or changing the widgets of the first?
Code I've written so far
You can do that- just call window.withdraw() on the Toplevel you need to hide after creating a new Toplevel. Changing the widgets in the first is also an option- if you like, you could always try a Notebook widget and disable manual flipping or just put each "screen" in a frame and grid_ or pack_forget them to remove them from the window.

Sliders and checkbtton in python 3 and tkinter

How can I make that when checkbutton is checked that then all Sliders move like one by using python 3 and tkinter?
Thanks for any help! :)
First, you will need to save a reference to each of your sliders, which are instances of the Scale widget. Next, you will need to associate a command with the checkbutton (using the command attribute) which will be called whenever the checkbutton is checked or unchecked. In that command you can call the set method of each slider.

wxPython update a listbox live

I am developing a programme using python & wxPython. I have a listbox, and I need for it to be updated live to be used as a log.
I have done this simply with the Append() function, but the text added to the listbox is not shown until the end of the procedure, instead of being shown when the Append command is executed. I know this because after each insertion I print the size of the listbox.
def writeLog(self, text):
self.log.Append(text)
print self.log.GetStrings().__len__()
Right now, for checking purposes, I am calling a script that has the following code:
parent.writeLog("aaaaaa")
sleep(1)
parent.writeLog("aaaaaa")
sleep(1)
parent.writeLog("aaaaaa")
I have tried these answers but I couldn't make them work for me:
Update a ListBox in wxPython
wxPython: Update wx.ListBox list
So, How can I see the listBox updated in the screen right after the writeLog function is called? Is it possible? Thanks!
You have a few options here, the easiest perhaps is to call wx.Yield() when you want the ui to be updated, so after your Append calls
Another solution would be to to get any text that needs adding in a separate thread, and then send it back to the main thread via a custom event or pubsub which can then Append to the listbox

How to create a restart button in wx.Python - Python

So I have a program that opens up and does stuff.. However, is there a way to either restart the frame that is open or is there a way to close and open the frame again without have to rerun the program?
You can use either:
frame.Iconize() to minimize your window
Hide it using methods:
window.Hide()
window.Show(n) with n= True or False
With the second alternative the frame disappears, so you need some method to call your frame back (maybe leaving visible a small parent or child frame with a button to call the hidden frame).
Edit: As #Fenikso indicates below, the best way to get back your hidden window is using wx.TaskBarIcon. You have an example in the comments below.

how to disable the window close button in pygame?

In a pygame application window, the minimize, resize and close buttons are present. Is there a way to disable the close(X) button?
I don't think there is, because some window managers don't give you the ability to remove the close button. But you can write an event handler such that the close button does whatever you want, including nothing.
Why do you want to prevent the user from closing? If it's just a matter that you would rather provide an in-game "quit" button that confirms and/or saves before quitting, you can perform the same task when the user hits the close button.
Just for the record, another option would be to pass the following argument to the set_mode() method call:
pygame.display.set_mode(..., flags = pygame.NOFRAME)
This however makes the whole frame go away, including the top strip to move the window around and the other buttons, such as minimize, so it's rather overkill for just getting rid of the X button.

Categories