-2

Hello Everyone i need help why my output result is none in the print('bla bla') line so from my output is None, None, None that actually insert from npm , nama , and jurusan but the output is none ,can anybody help me solve it thanks

import sqlite3
import tkinter
from tkinter import *
from tkinter import ttk



def Daftar():
    window = Tk()
    window.title("Welcome to TutorialsPoint")
    window.geometry('400x400')
    window.configure(background = "grey");

    Lnpm = Label(window, text="Please Input Your npm: ").grid(row=0, column=0)
    Lnama = Label(window,text="Please Input Your nama: ").grid(row=1, column=0)
    Ljurusan = Label(window,text="Please Input Your jurusan: ").grid(row=2, column=0)

    npm = Entry(window).grid(row = 0,column = 1)
    nama = Entry(window).grid(row = 1,column = 1)
    jurusan = Entry(window).grid(row = 2,column = 1)
 def Clicked():

     print("First Name: %s\nLast Name: %s\nLast Name: %s" % (npm, nama, jurusan))

     connect = sqlite3.connect('Presensi.db')
     cur = connect.cursor()
     connect.execute("INSERT OR IGNORE INTO user(npm,nama,jurusan) values(?,?,?)", (str(npm),str(nama),str(jurusan)))
     connect.execute("INSERT OR IGNORE INTO presensi(nama) values(?)", (str(nama),))
     connect.commit()
     cur.close()

    btn = ttk.Button(window ,text="Register",command= Clicked()).grid(row=3,column=0)
    window.mainloop()
  • Does this help? [tkinter-attributeerror-nonetype-object-has-no-attribute-attribute-name](https://stackoverflow.com/questions/1101750/tkinter-attributeerror-nonetype-object-has-no-attribute-attribute-name) – kusz Mar 30 '20 at 18:19
  • No Sorry, if i using that from the help u given, only pass without showing anything – marvin ariel johannes Mar 30 '20 at 19:05

1 Answers1

0

You've got two big issues here:

  • the grid() function of the Entry object returns None and that's what npm, nama and jurusan are None. What you have to do is store the Entry object, not the value returned from grid().
  • you're not calling get() on the Entry objects to get their input values

What you can do is create a class in which you store the Entry objects. The callback function of the Button object can then be a method of the class.

I've reorganised your code to do this:

from tkinter import Tk, Label, Button, Entry
import sqlite3

class Daftar:
    def __init__(self, master):
        self.window = master
        self.window.title("Welcome to TutorialsPoint")
        self.window.geometry('400x400')
        self.window.configure(background = "grey");

        self.Lnpm = Label(self.window, text="Please Input Your npm: ").grid(row=0, column=0)
        self.Lnama = Label(self.window,text="Please Input Your nama: ").grid(row=1, column=0)
        self.Ljurusan = Label(self.window,text="Please Input Your jurusan: ").grid(row=2, column=0)

        #Entry objects for later use
        self.npm = Entry(self.window)
        self.npm.grid(row = 0,column = 1)
        self.nama = Entry(self.window)
        self.nama.grid(row = 1,column = 1)
        self.jurusan = Entry(self.window)
        self.jurusan.grid(row = 2,column = 1)

        self.btn = Button(self.window ,text="Register",command = self.Clicked).grid(row=3,column=0)


    def Clicked(self):
        #Get the entry values
        npm = self.npm.get()
        nama = self.nama.get()
        jurusan = self.jurusan.get()
        print("First Name: %s\nLast Name: %s\nLast Name: %s" % (npm, nama, jurusan))

        connect = sqlite3.connect('Presensi.db')
        cur = connect.cursor()
        connect.execute("INSERT OR IGNORE INTO user(npm,nama,jurusan) values(?,?,?)", (npm,nama,jurusan))
        connect.execute("INSERT OR IGNORE INTO presensi(nama) values(?)", (nama,))
        connect.commit()
        cur.close()


root = Tk()
my_gui = Daftar(root)
root.mainloop()
window.mainloop()
jignatius
  • 6,304
  • 2
  • 15
  • 30