user3430502
user3430502

Reputation: 23

Calling class from same file with tkinter

I have this peace of code I designed but the problem is that I'm not good enough with calling a class back so that I can get the generated number without typing it back. Code:

from Tkinter import *
import tkMessageBox
import tkFont
import re

class Questionnaire(Frame):
def __init__(self, master):


    Frame.__init__(self, master)
    root.title("Survey")
    self.grid()
    self.createQuestHealth()




def createQuestHealth(self):
     studentNumber: float(102.02)

Here I want to call this number automatically without initializing a new number with new variable. I tried by:

one = Questionnaire()
val = one.get()

but it says :

TypeError: __init__() takes exactly 2 arguments (1 given)

I didn't get that at all ><

Upvotes: 1

Views: 54

Answers (1)

Marcin
Marcin

Reputation: 238199

The __init__ constructor for Questionnaire takes two arguments, self and master. When you make an instance of your class one = Questionnaire(), self is automatically assigned the the instance, but muster is missing. You should provide master/parent widget for your class. For example.

root = Tk()
one = Questionnaire(root)

Upvotes: 1

Related Questions