我已经了解了代码,但我无法理解为什么规模如此反应迟钝/慢。
from tkinter import *
#main menu
def mmWindow():
mmWindow=Tk()
mmWindow.geometry('600x600')
#Page 1
def page1():
master.title('Page 1')
# set up a boolean for each page, when page click turn one boolean true and the rest false
#look at frames, canvas looks like the main option
#draw sliders 1-6
Scale(master, from_=0, to=100).place(x=200, y=120)
#Page 2
def page2():
master.title('Page 2')
#draw sliders 7-12
Scale(master, from_=0, to=100).place(x=300, y=120)
#Page 3
def page3():
master.title('Page 3')
#draw slider 13-18
#Page 4
def page4():
master.title('Page 4')
#draw sldiers 19-24
#Presets
def presets():
master.title('Presets')
#settings
def settings():
master.title('Settings')
#first window
master= Tk()
master.geometry('1440x900+0+0')
master.title('DMX512 Controller')
#buttons
bw=250
bh=110
img1 = PhotoImage(file="/Users/Josh/Documents/Uni/Year3/Diss/Images/Gif/mainmenu.gif")
img2 = PhotoImage(file="/Users/Josh/Documents/Uni/Year3/Diss/Images/Gif/p1.gif")
img3 = PhotoImage(file="/Users/Josh/Documents/Uni/Year3/Diss/Images/Gif/p2.gif")
img4 = PhotoImage(file="/Users/Josh/Documents/Uni/Year3/Diss/Images/Gif/p3.gif")
img5 = PhotoImage(file="/Users/Josh/Documents/Uni/Year3/Diss/Images/Gif/p4.gif")
img6 = PhotoImage(file="/Users/Josh/Documents/Uni/Year3/Diss/Images/Gif/presets.gif")
img7 = PhotoImage(file="/Users/Josh/Documents/Uni/Year3/Diss/Images/Gif/settings.gif")
Button(master, image=img1, command =mmWindow, width=bw, height=bh).place(x=1190,y=0)
Button(master, image=img2,command =page1).place(x=1190,y=120)
Button(master, image=img3, command =page2).place(x=1190,y=240)
Button(master, image=img4,command =page3).place(x=1190,y=360)
Button(master, image=img5, command =page4).place(x=1190,y=480)
Button(master, image=img6,command =presets).place(x=1190,y=600)
Button(master, image=img7,command =settings).place(x=1190,y=720)
#text
wtitle = Label (master, text = "Pi DMX", fg = 'blue')
wtitle.place(x = 640, y = 100)
master.mainloop()
(我知道,我也没有以最环保的方式编写代码。)
答案 0 :(得分:1)
我遇到了同样的问题,并且创建了一个(相当难看的)解决方法,它围绕回调函数创建了一个包装器,因此每次调用回调函数时都会调用Frame the Scale的update()方法。如果不使用回调函数,则可以将self.update方法直接传递给Scale初始化程序的命令参数。
这种方法有效,但感觉不满意和黑客。
import tkinter as tk
class MainWindow(tk.Frame):
def __init__(self, master=None, callback_funcs=None, max_rows=8):
tk.Frame.__init__(self, master)
self.grid()
cb = lambda callback: lambda val: self.run_callback(callback, val)
self.callback_funcs = [cb(callback) for callback in callback_funcs]
self.max_rows = max_rows
self.create_scales()
def run_callback(self, callback, val):
self.update()
callback(val)
def create_scales(self):
self.scales = []
for callback in self.callback_funcs:
scale = tk.Scale(from_=0, to=1, resolution=0.01, command=callback, orient=tk.HORIZONTAL)
scale.grid()
答案 1 :(得分:-1)
如果您希望更改窗口大小,请使用.geometry
master.geometry('400x400')