[Solved] python variables between functions

Working example with global variable and two windows. It uses only one mainloop() and Toplevel() to create second window. import tkinter as tk # — functions — def main(): #inform function to use external/global variable global int_var # only if you will use `=` to change value root = tk.Tk() root.title(“Root”) # change global variable … Read more

[Solved] Tkinter Placing And Deleting A Label

In your code, the label is placed, and after 2 seconds it is destroyed. It is never actually shown in your window however as it is not updated. This is as when entering Tk’s mainloop, it updates the window in a loop, checking if changes have been made. In your case, you are preventing this … Read more

[Solved] How to make an on/off switch for a function in a python program?

Take a look at this example: from tkinter import * root = Tk() def run(): global rep if var.get() == 1: print(‘Hey’) rep = root.after(1000,run) #run the function every 2 second, if checked. else: root.after_cancel(rep) #cancel if the checkbutton is unchecked. def step(): print(‘This is being printed in between the other loop’) var = IntVar() … Read more

[Solved] Disable button in Tkinter (Python)

You need to unbind the event. state=”disabled”/state=DISABLED makes button disabled but it doesn’t unbind the event. You need to unbind the corresponding events to achieve this goal. If you want to enable the button again then you need to bind the event again. Like: from Tkinter import * def printSomething(event): print(“Print”) #Start GUI gui = … Read more

[Solved] A window which displays all the files(.txt, .docs, .docx, .pdf) of a folder/directory in python [closed]

Here is a simple example of getting the filenames inside of a given directory and displaying them as buttons to be selected from. This example will only work with a directory containing only text files but it should serve to provide a good example. Here I use the os import and use the method from … Read more

[Solved] How to destroy widgets?

Try this: import tkinter as tk root = tk.Tk() root.geometry(“500×300+10+13”) root.title(“Test”) b = tk.Button(root, text=”click me”) def onclick(evt): w = evt.widget w.destroy() b.bind(“<Button-1>”, onclick) b.pack() root.mainloop() 13 solved How to destroy widgets?

[Solved] Questions about lambda and eval in relation to some Python calculator GUI code [closed]

Assigned variables are just that. Assigned by the coder. I have variable_name = object. If there are Tkinter specific variables being used at some point it is most likely a PSEUDO-CONSTANT that is used in arguments within the methods of tkinter. You should never try to change predefined variables that are part of the tkinter … Read more

[Solved] How would I make a simple encryption/decryption program? [closed]

Use two dicts to do the mapping, one from letters to encryption_code and the reverse to decrypt: letters=”ABCDEFGHIJKLMNOPQRSTUVWXYZ” encryption_code=”LFWOAYUISVKMNXPBDCRJTQEGHZ” enc = dict(zip(letters,encryption_code)) dec = dict(zip(encryption_code, letters)) s = “HELLO WORLD” encr = “”.join([enc.get(ch, ch) for ch in s]) decr = “”.join([dec.get(ch, ch) for ch in encr]) print(encr) print(decr) Output: IAMMP EPCMO HELLO WORLD Using your … Read more

[Solved] Tkinter Function attached to Button executed immediately [duplicate]

The solution is to pass the function as a lambda: from Tkinter import * root =Tk() def callback(parameter): print parameter button = Button(root, text=”Button”, command=lambda: callback(1)) button.pack() root.mainloop() Also, as @nbro already correctly pointed out, the button attribute is command, not function. 1 solved Tkinter Function attached to Button executed immediately [duplicate]