Python ttk or TkInter widget design
I am searching for a way to create a brand new widget in ttk or Tkinter. I would like to have a widget a little like a mix between Scale and toggle button with multiple positions (parameter option) for being able to select different discret options. I'd like this thing to be fully compatible with the ttk module in Python.
Has anyone an idea of how to achieve that ?
Thanks.
Right now the ugly solution I made is this :
class Slider(ttk.Frame):
def __init__(self,parent=None,LabelSld = u'',fmt = '26',statelst=,Clist=,default=0,NrmLblLink = None):
ttk.Frame.__init__(self,parent)
self.pdx = 2
self.pdy = 1
self.Amttxt = Tkinter.StringVar()
self.Amttxt.set(format(LabelSld,fmt))
self.Amtlbl = ttk.Label(self,textvariable=self.Amttxt, anchor='ne')
self.Amtlbl.grid(padx=self.pdx,pady=self.pdy,column=0,row=0,sticky='nw')
self.Amt = Tkinter.StringVar()
self.Amt.set('')
self.AmtIntVar = Tkinter.IntVar()
self.AmtIntVar.set(0)
self.Lbl = ttk.Label(self)
self.Lbl.grid(column=0,row=1,sticky='ne')
self.Lbl.configure(foreground=Clist[0])
self.Lbl.configure(text=statelst[default])
self.StateLst = statelst
self.ColorLst = Clist
if NrmLblLink == None:
self.Slider = ttkw.TickScale(self,from_=0, to=len(statelst)-1,orient='horizontal', command = partial(scale_update,label=self.Lbl, clist = self.StateLst, color_list = self.ColorLst),resolution = 1,showvalue=0,tickinterval=1)
else:
self.Slider = ttkw.TickScale(self,from_=0, to=len(statelst)-1,orient='horizontal', command = partial(scale_update,label=self.Lbl, clist = self.StateLst, color_list = self.ColorLst, NrmLblLink = NrmLblLink),resolution = 1,showvalue=0,tickinterval=1)
self.Slider.grid(column=1,row=0,sticky='ew',rowspan=2)

python-2.7 user-interface widget ttk
add a comment |
I am searching for a way to create a brand new widget in ttk or Tkinter. I would like to have a widget a little like a mix between Scale and toggle button with multiple positions (parameter option) for being able to select different discret options. I'd like this thing to be fully compatible with the ttk module in Python.
Has anyone an idea of how to achieve that ?
Thanks.
Right now the ugly solution I made is this :
class Slider(ttk.Frame):
def __init__(self,parent=None,LabelSld = u'',fmt = '26',statelst=,Clist=,default=0,NrmLblLink = None):
ttk.Frame.__init__(self,parent)
self.pdx = 2
self.pdy = 1
self.Amttxt = Tkinter.StringVar()
self.Amttxt.set(format(LabelSld,fmt))
self.Amtlbl = ttk.Label(self,textvariable=self.Amttxt, anchor='ne')
self.Amtlbl.grid(padx=self.pdx,pady=self.pdy,column=0,row=0,sticky='nw')
self.Amt = Tkinter.StringVar()
self.Amt.set('')
self.AmtIntVar = Tkinter.IntVar()
self.AmtIntVar.set(0)
self.Lbl = ttk.Label(self)
self.Lbl.grid(column=0,row=1,sticky='ne')
self.Lbl.configure(foreground=Clist[0])
self.Lbl.configure(text=statelst[default])
self.StateLst = statelst
self.ColorLst = Clist
if NrmLblLink == None:
self.Slider = ttkw.TickScale(self,from_=0, to=len(statelst)-1,orient='horizontal', command = partial(scale_update,label=self.Lbl, clist = self.StateLst, color_list = self.ColorLst),resolution = 1,showvalue=0,tickinterval=1)
else:
self.Slider = ttkw.TickScale(self,from_=0, to=len(statelst)-1,orient='horizontal', command = partial(scale_update,label=self.Lbl, clist = self.StateLst, color_list = self.ColorLst, NrmLblLink = NrmLblLink),resolution = 1,showvalue=0,tickinterval=1)
self.Slider.grid(column=1,row=0,sticky='ew',rowspan=2)

python-2.7 user-interface widget ttk
add a comment |
I am searching for a way to create a brand new widget in ttk or Tkinter. I would like to have a widget a little like a mix between Scale and toggle button with multiple positions (parameter option) for being able to select different discret options. I'd like this thing to be fully compatible with the ttk module in Python.
Has anyone an idea of how to achieve that ?
Thanks.
Right now the ugly solution I made is this :
class Slider(ttk.Frame):
def __init__(self,parent=None,LabelSld = u'',fmt = '26',statelst=,Clist=,default=0,NrmLblLink = None):
ttk.Frame.__init__(self,parent)
self.pdx = 2
self.pdy = 1
self.Amttxt = Tkinter.StringVar()
self.Amttxt.set(format(LabelSld,fmt))
self.Amtlbl = ttk.Label(self,textvariable=self.Amttxt, anchor='ne')
self.Amtlbl.grid(padx=self.pdx,pady=self.pdy,column=0,row=0,sticky='nw')
self.Amt = Tkinter.StringVar()
self.Amt.set('')
self.AmtIntVar = Tkinter.IntVar()
self.AmtIntVar.set(0)
self.Lbl = ttk.Label(self)
self.Lbl.grid(column=0,row=1,sticky='ne')
self.Lbl.configure(foreground=Clist[0])
self.Lbl.configure(text=statelst[default])
self.StateLst = statelst
self.ColorLst = Clist
if NrmLblLink == None:
self.Slider = ttkw.TickScale(self,from_=0, to=len(statelst)-1,orient='horizontal', command = partial(scale_update,label=self.Lbl, clist = self.StateLst, color_list = self.ColorLst),resolution = 1,showvalue=0,tickinterval=1)
else:
self.Slider = ttkw.TickScale(self,from_=0, to=len(statelst)-1,orient='horizontal', command = partial(scale_update,label=self.Lbl, clist = self.StateLst, color_list = self.ColorLst, NrmLblLink = NrmLblLink),resolution = 1,showvalue=0,tickinterval=1)
self.Slider.grid(column=1,row=0,sticky='ew',rowspan=2)

python-2.7 user-interface widget ttk
I am searching for a way to create a brand new widget in ttk or Tkinter. I would like to have a widget a little like a mix between Scale and toggle button with multiple positions (parameter option) for being able to select different discret options. I'd like this thing to be fully compatible with the ttk module in Python.
Has anyone an idea of how to achieve that ?
Thanks.
Right now the ugly solution I made is this :
class Slider(ttk.Frame):
def __init__(self,parent=None,LabelSld = u'',fmt = '26',statelst=,Clist=,default=0,NrmLblLink = None):
ttk.Frame.__init__(self,parent)
self.pdx = 2
self.pdy = 1
self.Amttxt = Tkinter.StringVar()
self.Amttxt.set(format(LabelSld,fmt))
self.Amtlbl = ttk.Label(self,textvariable=self.Amttxt, anchor='ne')
self.Amtlbl.grid(padx=self.pdx,pady=self.pdy,column=0,row=0,sticky='nw')
self.Amt = Tkinter.StringVar()
self.Amt.set('')
self.AmtIntVar = Tkinter.IntVar()
self.AmtIntVar.set(0)
self.Lbl = ttk.Label(self)
self.Lbl.grid(column=0,row=1,sticky='ne')
self.Lbl.configure(foreground=Clist[0])
self.Lbl.configure(text=statelst[default])
self.StateLst = statelst
self.ColorLst = Clist
if NrmLblLink == None:
self.Slider = ttkw.TickScale(self,from_=0, to=len(statelst)-1,orient='horizontal', command = partial(scale_update,label=self.Lbl, clist = self.StateLst, color_list = self.ColorLst),resolution = 1,showvalue=0,tickinterval=1)
else:
self.Slider = ttkw.TickScale(self,from_=0, to=len(statelst)-1,orient='horizontal', command = partial(scale_update,label=self.Lbl, clist = self.StateLst, color_list = self.ColorLst, NrmLblLink = NrmLblLink),resolution = 1,showvalue=0,tickinterval=1)
self.Slider.grid(column=1,row=0,sticky='ew',rowspan=2)

python-2.7 user-interface widget ttk
python-2.7 user-interface widget ttk
edited Nov 30 '18 at 15:40
Andréa Loyer
asked Nov 15 '18 at 20:52
Andréa LoyerAndréa Loyer
466
466
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53327731%2fpython-ttk-or-tkinter-widget-design%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53327731%2fpython-ttk-or-tkinter-widget-design%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown