I am creating a game in python. there are 2 general managers (so 2 radio buttons). each GM can select from 8 goalies (these 8 selections are the check boxes). I am trying to write the code such that if GM 1 selects goalies A, B and C, then when GM 2 selects he/she cannot select goalies A, B and C, but can only choose from D, E, F, G, H; check boxes A, B, C would be greyed out. have searched reference material online but not been able to equate it to my below situation. Thanks in advance
import tkinter
import tkinter.messagebox
import pickle
MAXIMUM = 1
TOTAL = 0.0
CAP = 150000000
class CrudGUI:
def __init__(self, master):
self.master = master
self.master.title('NHL Draft')
self.top_frame = tkinter.Frame(self.master)
self.bottom_frame = tkinter.Frame(self.master)
self.label1 = tkinter.Label(self.top_frame, text='''Welcome to the NHL General Manager game''')
self.label1.pack(anchor='w', padx=200)
self.top_frame.pack()
self.bottom_frame.pack()
self.top_frame = tkinter.Frame(self.master)
self.bottom_frame = tkinter.Frame(self.master)
self.radio_var = tkinter.IntVar()
self.radio_var.set(1)
# create the radio buttons
self.gm1 = tkinter.Radiobutton(self.top_frame, text='General Manager 1',
variable=self.radio_var, value=1)
self.gm2 = tkinter.Radiobutton(self.top_frame, text='General Manager 2',
variable=self.radio_var, value=2)
# pack the radio buttons
self.gm1.pack(anchor='w', padx=200)
self.gm2.pack(anchor='w', padx=200)
# create ok and quit buttons
self.ok_button = tkinter.Button(self.bottom_frame, text='OK', command=self.open_menu)
self.quit_button = tkinter.Button(self.bottom_frame, text='QUIT', command=self.master.destroy)
# pack the buttons
self.ok_button.pack(side='left')
self.quit_button.pack(side='left')
# pack the frames
self.top_frame.pack()
self.bottom_frame.pack()
def open_menu(self):
if self.radio_var.get() == 1:
_ = Gm1GUI(self.master)
# elif self.radio_var.get() == 2:
# _ = Gm2GUI(self.master)
else:
tkinter.messagebox.showinfo('Function', 'still under construction')
class Gm1GUI:
def __init__(self, master):
self.gm1 = tkinter.Toplevel(master)
self.top_frame = tkinter.Frame(self.gm1)
self.bottom_frame = tkinter.Frame(self.gm1)
self.radio_var = tkinter.IntVar()
self.radio_var.set(1)
# create the radio buttons
self.goalies = tkinter.Radiobutton(self.top_frame, text='Goalies',
variable=self.radio_var, value=1)
# pack the radio buttons
self.goalies.pack(anchor='w', padx=200)
# create ok and quit buttons
self.ok_button = tkinter.Button(self.bottom_frame, text='OK', command=self.open_menu1)
self.quit_button = tkinter.Button(self.bottom_frame, text='QUIT', command=self.gm1.destroy)
# pack the buttons
self.ok_button.pack(side='left')
self.quit_button.pack(side='left')
# pack the frames
self.top_frame.pack()
self.bottom_frame.pack()
def open_menu1(self):
if self.radio_var.get() == 1:
_ = GoaliesGUI(self.gm1)
else:
tkinter.messagebox.showinfo('Function', 'still under construction')
class GoaliesGUI:
def __init__(self, master):
try:
input_file = open("team1.dat", 'rb')
self.team1 = pickle.load(input_file)
input_file.close()
except (FileNotFoundError, IOError):
self.team1 = {}
self.main_window = tkinter.Toplevel(master)
self.label1 = tkinter.Label(self.main_window, text='''Please select 3 Goalies \n''')
self.label1.pack()
self.top_frame = tkinter.Frame(self.main_window)
self.bottom_frame = tkinter.Frame(self.main_window)
self.cb_var1 = tkinter.IntVar()
self.cb_var2 = tkinter.IntVar()
self.cb_var3 = tkinter.IntVar()
self.cb_var4 = tkinter.IntVar()
self.cb_var5 = tkinter.IntVar()
self.cb_var6 = tkinter.IntVar()
self.cb_var7 = tkinter.IntVar()
self.cb_var8 = tkinter.IntVar()
self.cb_var1.set(0)
self.cb_var2.set(0)
self.cb_var3.set(0)
self.cb_var4.set(0)
self.cb_var5.set(0)
self.cb_var6.set(0)
self.cb_var7.set(0)
self.cb_var8.set(0)
self.cb1 = tkinter.Checkbutton(self.top_frame, text='Henrique Lundquist ', variable=self.cb_var1)
self.cb2 = tkinter.Checkbutton(self.top_frame, text='Cary Price ', variable=self.cb_var2)
self.cb3 = tkinter.Checkbutton(self.top_frame, text='Frederik Anderson ', variable=self.cb_var3)
self.cb4 = tkinter.Checkbutton(self.top_frame, text='Andrei Vasilevski ', variable=self.cb_var4)
self.cb5 = tkinter.Checkbutton(self.top_frame, text='Sergei Bobrovsky ', variable=self.cb_var5)
self.cb6 = tkinter.Checkbutton(self.top_frame, text='Jonathan Quick ', variable=self.cb_var6)
self.cb7 = tkinter.Checkbutton(self.top_frame, text='John Gibson ', variable=self.cb_var7)
self.cb8 = tkinter.Checkbutton(self.top_frame, text='Braden Holtby ', variable=self.cb_var8)
self.cb1.pack()
self.cb2.pack()
self.cb3.pack()
self.cb4.pack()
self.cb5.pack()
self.cb6.pack()
self.cb7.pack()
self.cb8.pack()
self.ok_button = tkinter.Button(self.bottom_frame, text='OK', command=self.show_selection)
self.quit_button = tkinter.Button(self.bottom_frame, text='Quit', command=self.main_window.destroy)
self.ok_button.pack(side='left')
self.quit_button.pack(side='left')
self.top_frame.pack()
self.bottom_frame.pack()
def show_selection(self):
global TOTAL
message = 'You selected the following Goalies: \n ' 'Player salaries are in USD: \n' '\n'
price = 0.00
for count in range(MAXIMUM):
if self.cb_var1.get() == 1:
message = message + 'Henrique Lundquist: $1,500,000\n'
price = price + float(1500000)
if self.cb_var2.get() == 1:
message = message + 'Cary Price: $10,500,000\n'
price = price + float(10500000)
if self.cb_var3.get() == 1:
message = message + 'Frederik Anderson: $5,000,000\n'
price = price + float(5000000)
if self.cb_var4.get() == 1:
message = message + 'Andrei Vasilevskiy: $4,000,000\n'
price = price + float(4000000)
if self.cb_var5.get() == 1:
message = message + 'Sergei Bobrovsky: $11,500,000\n'
price = price + float(11500000)
if self.cb_var6.get() == 1:
message = message + 'Jonathan Quick: $7,000,000\n'
price = price + float(7000000)
if self.cb_var7.get() == 1:
message = message + 'John Gibson: $6,400,000\n'
price = price + float(6400000)
if self.cb_var8.get() == 1:
message = message + 'Braden Holtby: $5,000,000\n'
price = price + float(5000000)
TOTAL += float(price)
print('The cumulative salary total of your selections so far is $', format(TOTAL, ',.0f'), sep='')
print('You have $', format(CAP - TOTAL, ',.0f'), 'available to pay other selections')
if TOTAL > CAP:
print("Please reselect. Your cumulative salary totals are greater than your salary cap")
tkinter.messagebox.showinfo('NHL Goalie selected ',
message + '\n' + 'Total of all salaries: ' + '$' + str(format(price, ',.0f')))
self.team1['Goalies'] = TOTAL
output_file = open('team1.dat', 'wb')
pickle.dump(self.team1, output_file)
output_file.close()
def main():
# create a window
root = tkinter.Tk()
_ = CrudGUI(root)
root.mainloop()
main()
Aucun commentaire:
Enregistrer un commentaire