'How can I get my loading circle GIF frames to display on a Tkinter Canvas?
I am having trouble getting a loading circle GIF to display on a Tkinter Canvas in my game's support window. My game is called Space Invaders Supreme, and it is built with pygame. I am using root.after() to make each frame display after a certain amount of time, so that the frames will appear to be 1 animated GIF. I have tried everything I can think of, but it still just won't display. If someone can help me, I would really appreciate it! Thanks in advance!
Here is the relevant code:
def setupLoadingCircleCanvasAndGIFFrames():
global loading_circle_canvas
global loading_circle_gif
global current_loading_circle_gif_frame_num
global loading_circle_gif_frames
loading_circle_gif_frames=[]
for i in range(number_of_loading_circle_gif_frames):
loading_circle_gif_frames.append(PhotoImage(file='loading_circle.gif', format='gif -index '+str(i)))
loading_circle_canvas=Canvas(width=96, height=54, bg='gray87', highlightthickness=0)
loading_circle_canvas.place(relx=0.5, rely=0.7, anchor=CENTER)
current_loading_circle_gif_frame_num=1
def switchToNextLoadingCircleGIFFrame():
global value_3
global current_loading_circle_gif_frame_num
current_loading_circle_gif_frame_num+=1
if current_loading_circle_gif_frame_num>152:
current_loading_circle_gif_frame_num=1
loading_circle_canvas.delete('all')
loading_circle_canvas.create_image(48, 27, image=loading_circle_gif_frames[current_loading_circle_gif_frame_num-1], anchor=CENTER)
loading_circle_canvas.itemconfig(1, state='normal')
value_3=support_win.after(50, switchToNextLoadingCircleGIFFrame)
def showLoadingCircleGIF():
global value_3
loading_circle_canvas.create_image(48, 27, image=loading_circle_gif_frames[0], anchor=CENTER)
loading_circle_canvas.itemconfig(1, state='normal')
value_3=support_win.after(50, switchToNextLoadingCircleGIFFrame)
def hideLoadingCircleGIF():
support_win.after_cancel(value_3)
loading_circle_canvas.destroy()
def submitFormIfSenderEmailValid():
if pag.confirm(text='Are you sure you want to submit this form?', title='Confirm Form Submission', buttons=['OK', 'Cancel'])=='OK':
try:
global support_win
global player_email_entry
global player_first_name_entry
global player_last_name_entry
global issue_type_dropdown
global issue_urgency_dropdown
global issue_description_st
global selected_attachments_st
global selected_attachment_info_strs
global selected_attachment_full_paths
player_email=player_email_entry.get()
player_first_name=player_first_name_entry.get()
player_last_name=player_last_name_entry.get()
issue_type_str=issue_urgency_dropdown.get()
issue_urgency_str=issue_urgency_dropdown.get()
issue_description=issue_description_st.get(1.0, END)
showLoadingCircleGIF()
o=og.OGESS(player_email, player_first_name, player_last_name, issue_type_str, issue_urgency_str, issue_description, selected_attachment_full_paths)
o.sendEmail()
hideLoadingCircleGIF()
except ValueError as error:
pag.alert(text='At least one of the required fields was given an invalid value, so the support request email could not be sent! Please fix the problem and try again!', button='OK')
except TypeError as error:
pag.alert(text='At least one of the required fields was given an invalid value, so the support request email could not be sent! Please fix the problem and try again!', button='OK')
def showSupportWindow():
global support_win
global player_email_entry
global player_first_name_entry
global player_last_name_entry
global issue_type_dropdown
global issue_urgency_dropdown
global issue_description_st
global selected_attachments_st
global selected_attachment_info_strs
global selected_attachment_full_paths
if game_state=='running':
global game_paused
game_paused=True
support_win=Tk()
support_win.title('Space Invaders Supreme -- Support')
support_win.geometry('1100x900')
support_win.resizable(False, False)
support_win.iconphoto(False, PhotoImage(file=r'C:\Users\willn\OneDrive\Documents\Code Folders\Python Code Files\PyGame Folders\Space Invaders Supreme Files\planet.png'))
support_win.configure(bg='gray87')
support_win_title_label=Label(support_win, text='Space Invaders Supreme -- Support', font=('Arial', 18, 'bold'), bg='white')
support_win_title_label.place(relx=0.5, rely=0.05, anchor=CENTER)
player_email_entry=Entry(support_win)
player_email_prompt_label=Label(support_win, text='Email:')
player_first_name_entry=Entry(support_win)
player_first_name_prompt_label=Label(support_win, text='First Name:')
player_last_name_entry=Entry(support_win)
player_last_name_prompt_label=Label(support_win, text='Last Name:')
player_email_prompt_label.place(relx=0.075, rely=0.125, anchor=CENTER)
player_first_name_prompt_label.place(relx=0.075, rely=0.175, anchor=CENTER)
player_last_name_prompt_label.place(relx=0.075, rely=0.225, anchor=CENTER)
player_email_entry.place(relx=0.25, rely=0.125, anchor=CENTER)
player_first_name_entry.place(relx=0.25, rely=0.175, anchor=CENTER)
player_last_name_entry.place(relx=0.25, rely=0.225, anchor=CENTER)
issue_type_dropdown=ttk.Combobox(support_win, state='readonly', values=['Bug', 'Question', 'Suggestion', 'Complaint', 'Report', 'Other'])
issue_type_prompt_label=Label(support_win, text='Issue Type:')
issue_urgency_dropdown=ttk.Combobox(support_win, state='readonly', values=['Very High', 'High', 'Average', 'Low', 'Very Low'])
issue_urgency_prompt_label=Label(support_win, text='Issue Urgency:')
issue_type_dropdown.current(0)
issue_urgency_dropdown.current(2)
issue_type_prompt_label.place(relx=0.075, rely=0.275, anchor=CENTER)
issue_urgency_prompt_label.place(relx=0.075, rely=0.325, anchor=CENTER)
issue_type_dropdown.place(relx=0.25, rely=0.275, anchor=CENTER)
issue_urgency_dropdown.place(relx=0.25, rely=0.325, anchor=CENTER)
issue_description_st=ScrolledText(support_win, wrap=WORD, width=30, height=9, font=('Arial', 9))
issue_description_prompt=Label(support_win, text='Issue Description:')
issue_description_prompt.place(relx=0.8, rely=0.125, anchor=CENTER)
issue_description_st.place(relx=0.8, rely=0.25, anchor=CENTER)
select_attachments_button=Button(support_win, text='Select Attachments', bg='gray', fg='white', command=showSelectAttachmentsDialog)
remove_attachments_button=Button(support_win, text='Remove Attachments', bg='gray', fg='white', command=showRemoveAttachmentsDialog)
selected_attachments_st=ScrolledText(support_win, wrap=WORD, width=60, height=3, font=('Arial', 9))
selected_attachment_info_strs=[]
selected_attachment_full_paths=[]
select_attachments_button.place(relx=0.5, rely=0.45, anchor=CENTER)
remove_attachments_button.place(relx=0.5, rely=0.6, anchor=CENTER)
selected_attachments_st.insert(1.0, 'Selected Attachments:\n')
selected_attachments_st.configure(state='disabled')
selected_attachments_st.place(relx=0.5, rely=0.525, anchor=CENTER)
reset_form_button=Button(support_win, text='Reset', bg='grey', fg='white', padx=52.25, command=resetSupportWindow)
submit_form_button=Button(support_win, text='Submit', bg='grey', fg='white', padx=52.25, command=submitFormIfSenderEmailValid)
reset_form_button.place(relx=0.4, rely=0.95, anchor=CENTER)
submit_form_button.place(relx=0.6, rely=0.95, anchor=CENTER)
setupLoadingCircleCanvasAndGIFFrames()
support_win.mainloop()
if game_state=='running':
game_paused=False
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
