1. I have written below code. It shows error.
Code & error are below.
2. What does this statement mean:
self.master=master
error:
Code & error are below.
2. What does this statement mean:
self.master=master
Code:
from Tkinter import *
import Tkinter
class menu1():
def __init__(self,master):
self.master = master
#clear value
self.val1 = 1
#default selection
self.v = IntVar()
self.v.set(1)
#create a label
self.x1 = Label(self,text="Title",justify = CENTER,padx = 100)
self.x1.pack()
#first radiobutton
self.x2 = Radiobutton(self,text="Title1",padx = 100,variable=self.v,value=1)
self.x2.pack(anchor=W)
#create button
self.x6 = Button(self,text="OK",command=self.submit)
self.x6.pack()
def submit(self):
self.val1 = self.v.get()
self.destroy()
def suicide(self):
self.val1 = 0
self.destroy()
def screen():
#create a root object
root = Tk()
app = menu1(root)
app.title("Option")
app.geometry("480x320")
app.mainloop()
return app.val1
screen();
error:
Code:
Traceback (most recent call last):
File "C:/Users/abc/Desktop/c.py", line 47, in <module>
screen();
File "C:/Users/abc/Desktop/c.py", line 41, in screen
app = menu1(root)
File "C:/Users/abc/Desktop/c.py", line 19, in __init__
self.x1 = Label(self,text="Title",justify = CENTER,padx = 100)
File "C:\Python27\lib\lib-tk\Tkinter.py", line 2591, in __init__
Widget.__init__(self, master, 'label', cnf, kw)
File "C:\Python27\lib\lib-tk\Tkinter.py", line 2081, in __init__
BaseWidget._setup(self, master, cnf)
File "C:\Python27\lib\lib-tk\Tkinter.py", line 2059, in _setup
self.tk = master.tk
AttributeError: menu1 instance has no attribute 'tk'
>>>