TypeError : ‘Tk’ Object is not callable

I’m writing a program which is supposed to connect to a server, check for DBs and look for a specific table (and how much items are in these tables), and I’m using Tkinter for the GUI.
The problem is whenever I try to use it, I have the error “TypeError : ‘Tk’ Object is not callable”
The program used to work, but it doesn’t anymore, have you guys got any idea about this ? ( Don’t worry about the strange names, I made this so I’m sure there are no problems, like a variable having the same name as a function or so)

import pyodbc
import sys
from tkinter import *

#wrote down variables here so I remembered them
username = ''
password = ''
server_name = ''
database = ''
table = 'véhicules'
nom_instance = ''
total = ''
nb_vehic = ''
master = Tk()

Label(master,text="What is the username ?").pack()
yzx = Entry(master)
yzx.pack()
username = yzx.get()
yzx.delete(0, END)

Label(master,text="What is this user's password?").pack()
yxz = Entry(master)
yxz.pack()
password = yxz.get()
yxz.delete(0, END)

Label(master, text="What is this server's IP adress ?").pack()
zyx = Entry(master)
zyx.pack()
server_name = zyx.get()
zyx.delete(0, END)

Label(master, text="which authority do you want to connect to ?").pack() #not sure about the traduction of this word, original is instance in french
xyz = Entry(master)
xyz.pack()
nom_instance=xyz.get()
xyz.delete(0, END)


def surelydoesntexist():
    connexion = "DRIVER={SQL Server};SERVER="+server_name+""+nom_instance+";Database=master;User Id="+username+";Password="+password #peut être ajouter Trusted_Connection=yes
#at this point, connect to the server and looks for the different DBs
    connect = pyodbc.connect(connexion)
    cursor = connect.cursor()

    for db in cursor.execute("select * from sys.databases"):
        try:
            connexion = ("DRIVER={SQL Server};SERVER="+server_name+""+nom_instance+";DATABASE="+db.name+";User Id="+username+";Password="+password)
            print ('%s ' % connexion)
            connect = pyodbc.connect(connexion)
            cursor = connect.cursor()
            cursor.execute("select count(*) from véhicules")
            row = cursor.fetchone()
            nb_vehic = row.user_count
            print ('%d items in this db' % row.user_count)
            total = total + int(nb_vehic)
        except: # catch *all* exceptions
            e = sys.exc_info()[0]
            print( "Error: %s" % e )

but = Button(master, text="Connect !", command=surelydoesntexist).pack

master()


Source: python

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.