Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tkinter sticky=N+W Error: global name 'N' is not defined

I am making a tkinter GUI but I am not getting why this error shows. Also, I am having trouble in understanding initializing Frame. Is that related to the error, maybe? I am still new to Python and need to understand more on how it works. Sorry, if the mistake will be basic, I am having a troubled mind. Your help will be appreciated. This is the code:

import Tkinter as tk
import string

class QueryInterface(tk.Frame):
  def __init__(self, master):
    tk.Frame.__init__(self, master)
    self.frame = tk.Frame(self.master)
    self.master.geometry("400x300+400+200")
    self.master.title("Thug Client-Side Honeypot")
    self.master.resizable(width = False, height = False)

    self.inputLabel = tk.Label(self, text = "Input arguments and URL:", font = "Calibri 11")
    self.inputLabel.grid(row = 1, column = 0, columnspan = 2, padx = 5, packy = 10, sticky = N+W)

    self.frame.pack()

def main():
  root = tk.Tk()
  app = QueryInterface(root)
  app.mainloop()

if __name__ == '__main__':
  main()

Here is the traceback:

Traceback (most recent call last):
    File "QueryInterface.py", line 71, in <module>
    main()
  File "QueryInterface.py", line 67, in main
    app = QueryInterface(root)
  File "QueryInterface.py", line 17, in __init__
     self.inputLabel.grid(row = 1, column = 0, columnspan = 2, padx = 5, packy = 10, sticky = N+W)
 NameError: global name 'N' is not defined
like image 265
sparklights Avatar asked Jun 05 '16 14:06

sparklights


1 Answers

As the error mentions, the problem is that you are referencing a variable N (as well as W) which are not defined.

These are variables defined in Tkinter, so you could do tk.N and tk.W, or alternatively just use the strings that those variables define, e.g.:

 self.inputLabel.grid(row = 1, column = 0, columnspan = 2, padx = 5, pady = 10, sticky = 'nw')

There are a couple of other issues that were preventing the code from running. You were creating a separate member Frame inside your QueryInterface which already inherits from Frame, and packing that.

This code runs.

import Tkinter as tk

class QueryInterface(tk.Frame):
  def __init__(self, master):
    tk.Frame.__init__(self, master)
    self.master.geometry("400x300+400+200")
    self.master.title("Thug Client-Side Honeypot")
    self.master.resizable(width = False, height = False)
    self.inputLabel = tk.Label(self, text = "Input arguments and URL:", font = "Calibri 11")
    self.inputLabel.grid(row = 1, column = 0, columnspan = 2, padx = 5, pady = 10, sticky = 'nw')
    self.pack()

def main():
  root = tk.Tk()
  app = QueryInterface(root)
  app.mainloop()

if __name__ == '__main__':
  main()
like image 66
Jeremy Gordon Avatar answered Nov 08 '22 18:11

Jeremy Gordon