<p>I want to get an information from button to pass an if conditional inside of an window</p> <p>Create function.</p> <p>Snippet modified:</p> <code><pre><span class="hljs-def">def _condition():</span> <span class="hljs-keyword">if not condition:</span> label = Label(window,text="hello this is a label") label.pack() button = Button(window,text="button",command=_condition) button.pack() </code>
Another approach is to create a function that will check the condition and then perform the desired action. For example:
def check_condition():
if condition:
label.configure(text="hello this is a label")
else:
label.configure(text="")
button = Button(window, text="button", command=check_condition)
button.pack()
In this example, the check_condition
function checks the value of the condition
variable and then sets the text of the label accordingly.
Finally, here is a response that involves creating a function to run two functions simultaneously:
from tkinter import *
def run_functions():
#condition
if yesvar.get() == 1:
show_label()
hide_label()
window = Tk()
window.geometry(('200x100'))
yesvar = IntVar()
yes = Checkbutton(window, variable=yesvar, text='yes, Run the functions')
yes.pack(side='top')
label = Label(window, text='')
label.pack(side='top')
lbl = Label(window, text='Welcome')
lbl.pack(side='top')
button = Button(window, text="button", command=run_functions)
button.pack(side='top')
window.mainloop()
In this example, the run_functions
function checks the value of the yesvar
variable and then calls the show_label
and hide_label
functions if the value is 1.