![]() |
Why is this not working? - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: GUI (https://python-forum.io/forum-10.html) +--- Thread: Why is this not working? (/thread-17453.html) |
Why is this not working? - gcryall - Apr-11-2019 from tkinter import * class TheEarnings(Frame): def __init__(self, root=None): Frame.__init__(self) self.root = root self.init_window() radioframe = Frame(root, width=120, height = 200, background="powder blue") self.radioframe.place(relx=.5, rely=.5, anchor="c") def init_window(self): self.root.title("The Ryall Family Earnings") self.pack(fill=BOTH, expand=1) self.create_radiobuttons() def create_radiobuttons(self): self.mode = IntVar() self.modetext = StringVar() self.modetext.set("Earnings") R1 = Radiobutton(radioframe, text="Assignments", variable=self.mode, value=1, command=self.string_table) R1.pack() R2 = Radiobutton(radioframe, text="Companies", variable=self.mode, value=2, command=self.string_table) R2.pack() R3 = Radiobutton(radioframe, text="Earnings", variable=self.mode, value=3, command=self.string_table) R3.pack() R4 = Radiobutton(radioframe, text="Employees", variable=self.mode, value=4, command=self.string_table) R4.pack() R5 = Radiobutton(radioframe, text="Programs", variable=self.mode, value=5, command=self.string_table) R5.pack() R6 = Radiobutton(radioframe, text="Rates", variable=self.mode, value=6, command=self.string_table) R6.pack() R7 = Radiobutton(radioframe, text="SpecialRateTypes", variable=self.mode, value=7, command=self.string_table) R7.pack() close_button = Button(radioframe, text="OK", command=self.quit) close_button.pack() def quit(): self.quit() def string_table(self): self.val = self.mode.get() if self.val == 1: self.tbl = "Assignments" elif self.val == 2: self.tbl = "Companies" elif self.val == 3: self.tbl = "Earnings" elif self.val == 4: self.tbl = "Employees" elif self.val == 5: self.tbl = "Programs" print(self.tbl) elif self.val == 6: self.tbl = "Rates" elif self.val == 7: self.tbl = "SpecialRateTypes" global table table = self.tbl root = Tk() root.title("The Ryall Family Earnings") root.geometry("1250x650") #creation of an instance app = TheEarnings(root) root.mainloop()How do I specify what frame the radionbuttons go into. I tried to specifying the self.radioframe frame that is defined in the the __init__ routine. But it’s not working. How do I specify what frame it’s in for radiobuttons. I’m attaching a screenshot and the radio buttons are supposed to be in the power blue frame. It seems that the radio bottons are outsider the powder blue frame. PS I tried posting with the screen shot but it isn't working RE: Why is this not working? - Larz60+ - Apr-11-2019 There are a bunch of reasons:
class TheEarnings(Frame): def __init__(self, root=None): Frame.__init__(self) self.root = root self.radioframe = Frame(root, width=120, height=200, background="powder blue") self.radioframe.place(relx=0.5, rely=0.5, anchor="c") self.init_window() def init_window(self): self.root.title("The Ryall Family Earnings") # self.pack(fill=BOTH, expand=1) self.create_radiobuttons() def create_radiobuttons(self): self.mode = IntVar() self.modetext = StringVar() self.modetext.set("Earnings") R1 = Radiobutton( self.radioframe, text="Assignments", variable=self.mode, value=1, command=self.string_table, ) R1.pack() R2 = Radiobutton( self.radioframe, text="Companies", variable=self.mode, value=2, command=self.string_table, ) R2.pack() R3 = Radiobutton( self.radioframe, text="Earnings", variable=self.mode, value=3, command=self.string_table, ) R3.pack() R4 = Radiobutton( self.radioframe, text="Employees", variable=self.mode, value=4, command=self.string_table, ) R4.pack() R5 = Radiobutton( self.radioframe, text="Programs", variable=self.mode, value=5, command=self.string_table, ) R5.pack() R6 = Radiobutton( self.radioframe, text="Rates", variable=self.mode, value=6, command=self.string_table, ) R6.pack() R7 = Radiobutton( self.radioframe, text="SpecialRateTypes", variable=self.mode, value=7, command=self.string_table, ) R7.pack() close_button = Button(self.radioframe, text="OK", command=self.quit) close_button.pack() def quit(self): self.root.destroy() def string_table(self): self.val = self.mode.get() if self.val == 1: self.tbl = "Assignments" elif self.val == 2: self.tbl = "Companies" elif self.val == 3: self.tbl = "Earnings" elif self.val == 4: self.tbl = "Employees" elif self.val == 5: self.tbl = "Programs" print(self.tbl) elif self.val == 6: self.tbl = "Rates" elif self.val == 7: self.tbl = "SpecialRateTypes" global table table = self.tbl def main(): root = Tk() root.title("The Ryall Family Earnings") root.geometry("1250x650") # creation of an instance app = TheEarnings(root) root.mainloop() if __name__ == '__main__': main() [python] from tkinter import * class TheEarnings(Frame): def __init__(self, root=None): Frame.__init__(self) self.root = root self.radioframe = Frame(root, width=120, height=200, background="powder blue") self.radioframe.place(relx=0.5, rely=0.5, anchor="c") self.init_window() def init_window(self): self.root.title("The Ryall Family Earnings") # self.pack(fill=BOTH, expand=1) self.create_radiobuttons() def create_radiobuttons(self): self.mode = IntVar() self.modetext = StringVar() self.modetext.set("Earnings") R1 = Radiobutton( self.radioframe, text="Assignments", variable=self.mode, value=1, command=self.string_table, ) R1.pack() R2 = Radiobutton( self.radioframe, text="Companies", variable=self.mode, value=2, command=self.string_table, ) R2.pack() R3 = Radiobutton( self.radioframe, text="Earnings", variable=self.mode, value=3, command=self.string_table, ) R3.pack() R4 = Radiobutton( self.radioframe, text="Employees", variable=self.mode, value=4, command=self.string_table, ) R4.pack() R5 = Radiobutton( self.radioframe, text="Programs", variable=self.mode, value=5, command=self.string_table, ) R5.pack() R6 = Radiobutton( self.radioframe, text="Rates", variable=self.mode, value=6, command=self.string_table, ) R6.pack() R7 = Radiobutton( self.radioframe, text="SpecialRateTypes", variable=self.mode, value=7, command=self.string_table, ) R7.pack() close_button = Button(self.radioframe, text="OK", command=self.quit) close_button.pack() def quit(self): self.root.destroy() def string_table(self): self.val = self.mode.get() if self.val == 1: self.tbl = "Assignments" elif self.val == 2: self.tbl = "Companies" elif self.val == 3: self.tbl = "Earnings" elif self.val == 4: self.tbl = "Employees" elif self.val == 5: self.tbl = "Programs" print(self.tbl) elif self.val == 6: self.tbl = "Rates" elif self.val == 7: self.tbl = "SpecialRateTypes" global table table = self.tbl def main(): root = Tk() root.title("The Ryall Family Earnings") root.geometry("1250x650") # creation of an instance app = TheEarnings(root) root.mainloop() if __name__ == '__main__': main() RE: Why is this not working? - Axel_Erfurt - Apr-11-2019 you must change all radioframe to self.radioframe and do self.init_window() later#!/usr/bin/python3 # -*- coding: utf-8 -*- from tkinter import * class TheEarnings(Frame): def __init__(self, root=None): Frame.__init__(self) self.root = root self.radioframe = Frame(root, width=120, height = 200, background="powder blue") self.radioframe.place(relx=.5, rely=.5, anchor="c") self.init_window() def init_window(self): self.root.title("The Ryall Family Earnings") self.pack(fill=BOTH, expand=1) self.create_radiobuttons() def create_radiobuttons(self): self.mode = IntVar() self.modetext = StringVar() self.modetext.set("Earnings") R1 = Radiobutton(self.radioframe, text="Assignments", variable=self.mode, value=1, command=self.string_table) R1.pack() R2 = Radiobutton(self.radioframe, text="Companies", variable=self.mode, value=2, command=self.string_table) R2.pack() R3 = Radiobutton(self.radioframe, text="Earnings", variable=self.mode, value=3, command=self.string_table) R3.pack() R4 = Radiobutton(self.radioframe, text="Employees", variable=self.mode, value=4, command=self.string_table) R4.pack() R5 = Radiobutton(self.radioframe, text="Programs", variable=self.mode, value=5, command=self.string_table) R5.pack() R6 = Radiobutton(self.radioframe, text="Rates", variable=self.mode, value=6, command=self.string_table) R6.pack() R7 = Radiobutton(self.radioframe, text="SpecialRateTypes", variable=self.mode, value=7, command=self.string_table) R7.pack() close_button = Button(self.radioframe, text="OK", command=self.quit) close_button.pack() def quit(): self.quit() def string_table(self): self.val = self.mode.get() if self.val == 1: self.tbl = "Assignments" elif self.val == 2: self.tbl = "Companies" elif self.val == 3: self.tbl = "Earnings" elif self.val == 4: self.tbl = "Employees" elif self.val == 5: self.tbl = "Programs" print(self.tbl) elif self.val == 6: self.tbl = "Rates" elif self.val == 7: self.tbl = "SpecialRateTypes" global table table = self.tbl root = Tk() root.title("The Ryall Family Earnings") root.geometry("1250x650") #creation of an instance app = TheEarnings(root) root.mainloop() |