Reputation: 37
For some reason the button in my code just wont appear on the page:
def roto_peen():
Z = StringVar()
Z.set("-")
def roto_calc():
x = float(first_strip.get())
y = float(second_strip.get())
Z.set((x - y) / x * .77)
result.config(text=f"{Z}")
roto = ncr_field(root)
roto.toplevel()
roto.set_title("P")
roto.set_geometry("400x300")
roto_frame = ncr_field(roto.widget)
roto_frame.labelframe(width=250, height=60, text='')
roto_frame.set_grid(row=0, col=0, columnspan=3, padx=20, pady=6)
roto_frame.widget.grid_propagate(False)
ncr_fields.append(roto_frame)
first_strip = ncr_field(roto_frame.widget)
first_strip.entry(hint_text="First Strip", font=("Helvetica", 12), width=20)
first_strip.set_grid(row=0, col=0, padx=20)
ncr_fields.append(first_strip)
second_strip = ncr_field(roto_frame.widget)
second_strip.entry(hint_text="Second Strip", font=("Helvetica", 12), width=20)
second_strip.set_grid(row=1, col=0, padx=20)
ncr_fields.append(second_strip)
result = ncr_field(roto.widget)
result.label(textvariable=Z, text='')
result.set_grid(col= 1, row=1)
submit = ncr_field(roto.widget)
submit.button(text="Calculate", command=roto_calc)
submit.set_grid(row=2, col=0, padx=20)
ncr_fields.append(submit_peen)
And on my import file:
def button(self, text, command):
self.widget = Button(text=text, command=command)
def set_grid(self, row, col, **kw):
self.widget.grid(row=row, column=col, **kw)
def set_geometry(self, geometry):
self.widget.geometry(geometry)
def set_title(self, title):
self.widget.title(title)
enter code here
def label(self, text, textvariable):
self.widget = Label(self.master, height=1, text=text, textvariable=textvariable)
def labelframe(self, text, width, height, **kwargs) :
self.widget = LabelFrame(self.master, width=width, height=height, text=text, **kwargs)
Hoping I got everything relevent but.. when I open the page, the button just doesnt appear when obvious it has a .grid placement.
What am I missing?
Upvotes: 0
Views: 178
Reputation: 46669
You forget passing self.master
to Button()
inside ncr_field.button()
function, so it should be:
def button(self, text, command):
self.widget = Button(self.master, text=text, command=command)
Upvotes: 1