python - Tkinter basic exapmle

Maybe this is the simplest example of Tkinter in action. but in case that you may want to copy and start the tkinter code.
from tkinter import *
import sys 

if __name__ == '__main__':
    win = Tk()
    button = Button(win, text = "Goodbye", command = sys.exit)
    button.pack()
    mainloop()

I have one word on the mainloop method, on different platform or IDE (especially the IDLE) have a caveat on the use of the mainloop. 
it is not necessary to use the mainloop at the end of the IDLE , because the IDLE on different platform may have different mode, because it is possible that the IDLE may be running in so called No Subprocess mode, where the IDLE is already running with the IDLE environment, running a separate mainloop will probably end up in hang.

你可能感兴趣的:(python)