def __init__(self, master): super().__init__(master, controller=None) self.gender_radio_group = CustomRadioGroup(self.frame, None) self.gender_radio_group.add("male", "male") self.gender_radio_group.add("female", "female") self.lbl_fname = LabelAndValue(self.frame, None, "name", label_length=10, value_length=40) self.lbl_falias = LabelAndValue(self.frame, None, "alias", label_length=10, value_length=40) self.btn_rnd = ttk.Button(self.frame, text="random", command=self.random_name) self.gender_radio_group.frame.grid(column=0, row=0, sticky=(W, N)) self.lbl_fname.frame.grid(column=0, row=1) self.lbl_falias.frame.grid(column=0, row=2) self.btn_rnd.grid(column=0, row=3) self.frame.grid(row=0, column=0, sticky = (N, E, W, S)) self.male_fnames = TableModel() self.female_fnames = TableModel() self.last_names = TableModel() self.first_aliases = TableModel() self.last_aliases = TableModel() self.male_fnames.load_table('first_names', 'male', 'default') self.female_fnames.load_table('first_names', 'female', 'default') self.first_aliases.load_table('first_aliases', 'all', 'default') self.last_aliases.load_table('last_aliases', 'all', 'default') self.last_names.load_table('last_names', 'all', 'default') self.db = dbManager()
class MainScreen(UIObject): def __init__(self, master): super().__init__(master, controller=None) self.gender_radio_group = CustomRadioGroup(self.frame, None) self.gender_radio_group.add("male", "male") self.gender_radio_group.add("female", "female") self.lbl_fname = LabelAndValue(self.frame, None, "name", label_length=10, value_length=40) self.lbl_falias = LabelAndValue(self.frame, None, "alias", label_length=10, value_length=40) self.btn_rnd = ttk.Button(self.frame, text="random", command=self.random_name) self.gender_radio_group.frame.grid(column=0, row=0, sticky=(W, N)) self.lbl_fname.frame.grid(column=0, row=1) self.lbl_falias.frame.grid(column=0, row=2) self.btn_rnd.grid(column=0, row=3) self.frame.grid(row=0, column=0, sticky = (N, E, W, S)) self.male_fnames = TableModel() self.female_fnames = TableModel() self.last_names = TableModel() self.first_aliases = TableModel() self.last_aliases = TableModel() self.male_fnames.load_table('first_names', 'male', 'default') self.female_fnames.load_table('first_names', 'female', 'default') self.first_aliases.load_table('first_aliases', 'all', 'default') self.last_aliases.load_table('last_aliases', 'all', 'default') self.last_names.load_table('last_names', 'all', 'default') self.db = dbManager() def random_name(self, *args): full_name = '' if self.gender_radio_group.variable.get() == 'male': fname = self.male_fnames.get_random_choice() full_name = fname.data['name'] else: fname = self.female_fnames.get_random_choice() full_name = fname.data['name'] lname = self.last_names.get_random_choice().data['name'] full_name = full_name + ' ' + lname self.lbl_fname.set(full_name) falias = self.first_aliases.get_random_choice() lalias = self.last_aliases.get_random_choice() alias = falias.data['name'] + " " + lalias.data['name'] self.lbl_falias.set(alias)