我试图在Tkinter中设置一个帧的动画,但我无法这样做。当我想更新滑块时,我会看到一个没有响应的白色屏幕。我也跟着其他例子做了一个实验
self.after(1000, self.UpdateSliders)
及
app.mainloop()
但是因为我使用的是框架,当点击一个按钮时,我会把它们换掉,所以它不会刷新框架。 如何刷新滑块以在该帧上移动
用于交换帧的代码
# Setup and declaring pages
class SoundBoard(Tk):
def __init__(self, *args, **kwargs):
Tk.__init__(self, *args, **kwargs)
# Window Config
self.title("Sound Board")
self.geometry('975x500')
self.iconbitmap(FileDir + 'Images/Icons/Black Icon.ico')
#Setting Up frames for each window
container = Frame(self)
container.pack(side="top", fill="both", expand = True)
container.grid_rowconfigure(0, weight=1)
container.grid_columnconfigure(0, weight=1)
#Create a blank dictionary which will be populated later
self.frames = {}
#Populate dictionary with all the pages (frame) in which the program uses
for F in (MainWindow,
ButtonsWindow,
SliderWindow,
DisplayWindow,
):
frame = F(container, self)
self.frames[F] = frame
frame.grid(row=0, column=0, sticky="nsew")
frame.configure(bg='#1b191a')
# Show the Main window
self.show_frame(MainWindow)
# Moves the frame to the front
def show_frame(self, cont):
frame = self.frames[cont]
frame.tkraise()
我希望滑块在其中更新的大型机代码
class MainWindow(Frame):
def __init__(self, parent, controller):
Frame.__init__(self,parent)
# Set up sliders
self.Slider1 = Slider(self,100,60,200,15,15,35,0,80,"White","Black")
self.Slider2 = Slider(self,100,60,200,15,15,35,0,80,"White","Black")
self.Slider3 = Slider(self,100,60,200,15,15,35,0,80,"White","Black")
self.Slider4 = Slider(self,100,60,200,15,15,35,0,80,"White","Black")
self.Slider5 = Slider(self,100,60,200,15,15,35,0,80,"White","Black")
self.Slider6 = Slider(self,100,60,200,15,15,35,0,80,"White","Black")
while True:
self.after(1000, self.UpdateSliders)
# Set value of the sliders
def UpdateSliders(self):
self.Slider1.SetVal(self.Board1, SavedInfo.ReadSliders("Slider1"))
self.Slider2.SetVal(self.Board1, SavedInfo.ReadSliders("Slider2"))
self.Slider3.SetVal(self.Board1, SavedInfo.ReadSliders("Slider3"))
self.Slider4.SetVal(self.Board1, SavedInfo.ReadSliders("Slider4"))
self.Slider5.SetVal(self.Board1, SavedInfo.ReadSliders("Slider5"))
self.Slider6.SetVal(self.Board1, SavedInfo.ReadSliders("Slider6"))
self.update()
print("S")
我为您编写了一个示例代码,其中包含手动和自动更改选项卡。我希望能从中学到有用的东西
我用更多的注释更新了代码,并在激活状态下的自动按钮上更改了颜色
相关问题 更多 >
编程相关推荐