First of all note that I am doing all these in Enthought/Canopy.
I have this basic GUI where it has 4 entry boxes in which you type stuff, and then you hit a button and it prints the stuff you entered. However, it is not operating the way I want it to. When you start the code and type in values and press the button, it won't do anything, then you close the gui window and it will print the values you entered.
Also, when you entered the values and hit the button once, again it won't do anything, but if you hit the button again it will print the values but not as expected. Say you entered 1, 2, 3, 4 and hit the button twice, the thing you see on the screen is 1, 2, 3, 4, 1 and when you close the window now, it will print out the rest.
I'd appreciate if you people can help me out with this. Thank you in advance. Below is my code:
Update: This issue does not happen with IDLE, but only Canopy.
from Tkinter import *
class Application:
def printcmd(self):
print(self.entrybox.get())
def __init__(self, master):
self.entrybox = Entry(master)
self.button = Button(master, text="print", command = self.printcmd)
self.entrybox.grid()
self.button.grid()
root = Tk()
Application(root)
root.mainloop()
If you are doing this in the Canopy GUI, you should ensure that Qt is not already set as the GUI backend. See https://support.enthought.com/hc/en-us/articles/204469880-Using-Tkinter-Turtle-or-Pyglet-in-Canopy-s-IPython-panel
For the print lag: Python buffers its output. If you want to ensure that some output is printed immediately, follow the print statement with sys.stdout.flush()
to flush the print output buffers. (Of course you must first import sys
.)
This can be an issue in any Python program. It arises more frequently in Canopy than in IDLE because Canopy used IPython's QtConsole which separates the execution kernel from the front end terminal-like panel into two separate OS processes.