1. I have written below code. It shows error.
Code & error are below.
2. What does this statement mean:
self.master=master
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();
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'
>>>
- Your Menu1 class should probably inherit from a default tkinter class.
- mainloop() should be called on the root object.
- self.master = master causes the method parameter called master to be stored in the member variable (self.master) so that it can be accessed later, in another method.
It means you are trying to bite more than you can chew.
Not to discourage you, but maybe you should gain some experience in working more on python before you can get started with tkinter
Tkinter, if memory serves correctly, is python's answer to Qt.
And yes, you should also read up and understand OOPs concepts and general programming methodologies.
Wiki is a good place to start and you can always buy books based on what you would like to pursue.
(Mike McGrath - pythons book comes to mind) It is a good read for a beginner.
...and what does this have to do with electronics? I was hoping you'd at least mention "Arduino".