1

I've got my head around the code, but I can't understand why the scale is so unresponsive/slow.

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()

(I know, I've not gone about writing my code in the most eco friendly way, too.)

finefoot
  • 9,914
  • 7
  • 59
  • 102
user2996828
  • 1,137
  • 3
  • 12
  • 19
  • Are you certain this exact code is causing the problem? When I run your code (with modifications because I don't have all your images), press a couple of buttons to get the sliders to appear, and them move the sliders, they work exactly as I expect, with no slowdown whatsoever. – Bryan Oakley Dec 18 '13 at 01:40
  • Unrelated to the question you asked, I strongly recommend you use grid or pack instead of place. Place is considerably harder to use, if you care about your GUI resizing properly, handling different fonts, and working on different resolutions. Pretty much nobody writes GUIs of any complexity at all using place. – Bryan Oakley Dec 18 '13 at 01:42
  • Thanks guys, I will look into guru and pack and I have a feeling it's my machine, I will try another tonight thanks – user2996828 Dec 18 '13 at 11:55

2 Answers2

2

I had the same issue, and created a (rather ugly) workaround that created a wrapper around the callback functions, so that the update() method of the Frame the Scale is placed in was called everytime the callback function was called. If you don't use a callback function, you could pass the self.update method directly to the command argument of the Scale initializer.

This method works, but feels unsatisfying and hackish.

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()
mart
  • 440
  • 4
  • 9
0

If you want the size of the window to change use .geometry

master.geometry('400x400')
Jordanian
  • 25
  • 10
  • I don't want the size of window to change, when I ran the code on my screen and tried to move the fader and it was really laggy, changed around every 4 seconds and jumped to values rather than just running smoothly..... – user2996828 Dec 18 '13 at 00:11