[Solved] Where to get the positions of the last item in the Listbox (python and tkinter)?

[ad_1] You can get the numerical index of the last item with the documented index command, passing in the special string “end”: last_index = the_listbox.index(“end”) To get the value of the last item you can use “end” in the get method as well: last_value = the_listbox.get(“end”) To make sure that the last item in the … Read more

[Solved] Tkinter – how do I change the title?

[ad_1] If you are meaning a setting title of your tkinter window by “this”. You have several options. Option 1 if __name__ == ‘__main__’: your_gui = YourGUI() your_gui.title(‘My Title’) # Set title your_gui.mainloop() Option 2 def __init__(self): # inherit tkinter’s window methods tk.Tk.__init__(self) self.title(‘My Title’) # Set title ……. tk.Button(self, text=”exit!”, command=self.EXITME).grid(row=4, column=0, columnspan=2) Both … Read more

[Solved] Python: Add Button via Tkinter

[ad_1] This has nothing to do with your specific Button Code. Indentation Error occur, when your formatting is wrong. your lines always start with a specified number of blanks or tabs (called Indentation). somewhere this went wrong. To get rid of this, check all your Indents in the beginning of your lines. And very important … Read more

[Solved] Cannot convert string to float in Python 3 [duplicate]

[ad_1] You’re setting your StringVar’s wrong… textvariable = “self.var” + str(x) This is just a string. Not a reference to the StringVar. In your calc function you’re doing this: >>> float(”) Traceback (most recent call last): File “<stdin>”, line 1, in <module> ValueError: could not convert string to float: Because your StringVar has no “value” … Read more

[Solved] How do I refresh tkinter window totally in python with a refresh button [closed]

[ad_1] The simplest way is to implement the entire window as a subclass of a tk Frame, and then destroy and recreate it. Your code might look something like this: import Tkinter as tk class Example(tk.Frame): def __init__(self, parent): tk.Frame.__init__(self, parent) <other code here…> class Application: def __init__(self): self.root = tk.Tk() self.frame = None refreshButton … Read more

[Solved] menubar not defined in python

[ad_1] You are missing some important parts here. You need to configure the menu first and you also need to add the cascade label. Take a look at this code. import tkinter def hey(): print(“hello”) def myNew(): # you forgot to use tkinter.Label here. mlabel = tkinter.Label(root, text=”yo”).pack() root = tkinter.Tk() root.title(“Wizelane”) root.geometry(‘400×80+350+340’) my_menu = … Read more

[Solved] Tkinter, try to keep using the program on while executing

[ad_1] You can use root.after(miliseconds, function_name, argument) to execute function with delay and root.mainloop() (and program) will work normally. You can use datetime to convert text to datetime object, substract two dates and get difference in milliseconds. try: import tkinter as tk import tkinter.messagebox as tkMessageBox print(“Python 3”) except: import Tkinter as tk import tkMessageBox … Read more

[Solved] Function to switch between two frames in tkinter

[ad_1] You shouldn’t put any logic in a lambda. Just create a normal function that has any logic you want, and call it from the button. It’s really no more complicated that that. class SomePage(…): def __init__(…): … button1 = tk.Button(self, text=”Back to Home”, command=lambda: self.maybe_switch_page(StartPage)) … def maybe_switch_page(self, destination_page): if …: self.controller.show_frame(destination_page) else: … … Read more

[Solved] ‘IndexError: list index out of range’ – reading & writing from same csv file [closed]

[ad_1] For anyone who has the same problem in the future, the solution is to remove the extra line. writer=csv.DictWriter(f,fieldnames=fieldnames, lineterminator=”\n”) Although it can be read with the extra line spacing by changing This: namesList = [x[0] for x in people] To this: namesList = [x[0:1] for x in people] (in my example) blank results … Read more

[Solved] How to amend (e.g. add/remove) the values of a ttk.Treeview tag (tkinter)?

[ad_1] According to the tcl documentation, a ttk.Treeview widget does have commands to add and remove a tag from a node or a list of nodes. However, these methods are not provided in the official tkinter wrapper; see the Treeview class in /usr/lib/python3.8/tkinter/ttk.py. Building on the comment by @JasonYang and answer by @CoolCloud, the test … Read more