Tkinter: AttributeError: NoneType object has no attribute

The grid, pack and place functions of the Entry object and of all other widgets returns None. In python when you do a().b(), the result of the expression is whatever b() returns, therefore Entry(…).grid(…) will return None. You should split that on to two lines like this: entryBox = Entry(root, width=60) entryBox.grid(row=2, column=1, sticky=W) That … Read more

How to center a window on the screen in Tkinter?

The simplest (but possibly inaccurate) method is to use tk::PlaceWindow, which takes the pathname of a toplevel window as an argument. The main window’s pathname is . import tkinter root = tkinter.Tk() root.eval(‘tk::PlaceWindow . center’) second_win = tkinter.Toplevel(root) root.eval(f’tk::PlaceWindow {str(second_win)} center’) root.mainloop() The problem Simple solutions ignore the outermost frame with the title bar and … Read more

Tkinter scrollbar for frame

Here’s example code adapted from the VerticalScrolledFrame page on the now defunct Tkinter Wiki that’s been modified to run on Python 2.7 and 3+. try: # Python 2 import tkinter as tk import tkinter.ttk as ttk from tkinter.constants import * except ImportError: # Python 2 import Tkinter as tk import ttk from tkinter.constants import * … Read more

Tkinter understanding mainloop

tk.mainloop() blocks. It means that execution of your Python commands halts there. You can see that by writing: while 1: ball.draw() tk.mainloop() print(“hello”) #NEW CODE time.sleep(0.01) You will never see the output from the print statement. Because there is no loop, the ball doesn’t move. On the other hand, the methods update_idletasks() and update() here: … Read more

Why is my Button’s command executed immediately when I create the Button, and not when I click it? [duplicate]

Consider this code: b = Button(admin, text=”as”, command=button(‘hey’)) It does exactly the same as this: result = button(‘hey’) b = button(admin, text=”as”, command=result) Likewise, if you create a binding like this: listbox.bind(“<<ListboxSelect>>”, some_function()) … it’s the same as this: result = some_function() listbox.bind(“<<ListboxSelect>>”, result) The command option takes a reference to a function, which is … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)