loops - mainloop() function in python -


i confused put mainloop function in python. when use code:

from tkinter import * import sys window = tk() def mainfunct():     while true:          label = label(window,text="hello world")         label2 = label(window, text = "hello world2")         menu = input("please input something")         if menu == "a":             label.pack()         if menu == "b":             label2.pack()         if menu == "c":             sys.exit()          window.mainloop() mainfunct() 

i want label packed when user inputs , when user inputs b want label2 packed. not sure when , why use mainloop. right when run program, gui pops after have inputted , can't input else , think has thing window.mainloop() function because loops on , on again instead of running while true loop again.

i able understand question better based off of comment. let me know if you're looking for:

import tkinter tk  class helloworld(tk.tk):     def __init__(self):         tk.tk.__init__(self)         self.entry = tk.entry(self)         self.button = tk.button(self, text="what's input?", command=self.on_button)         self.button.pack()         self.entry.pack()      def on_button(self):         answer = self.entry.get()         if answer == "a":             print("hello world")         elif answer == "b":             print("hello world 2")         elif answer == "c":             root.destroy()  root = helloworld() root.mainloop() 

so when dealing input of user it's better create class , obtain/compare information.

now if answer other a, b, or c there no response program, adjust accordingly.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -