Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I would like to change the default behaviors of various widgets. In particular I want to set the default relief of labels to SUNKEN, the default background to grey, the default foreground to blue, etc....

I have tried add_option, but the only thing that took was "*font","arial 32".

I wish to do this as I have one screen that has many labels on it and the code gets messy with the same relief=SUNKEN line after line.

Thanks

    self.PartInputFrame=Frame(self.parent,width=self.parent.winfo_screenwidth(),height=self.parent.winfo_screenheight())
    self.PartInputFrame.pack_propagate(0)
    self.PartInputFrame.config(background='blue')

    self.PartInputLabel=Label(self.PartInputFrame,anchor=CENTER)
    self.PartInputLabel.config(fg='white',bg='blue')
    self.PartInputLabel.config(text='Part Program Input Information')
    self.PartInputLabel.place(rely=.1,relx=.5,anchor=CENTER)
    self.PartInputLabel.config(font=("arial",32))


    self.PartInputFrame.option_add("*Font","arial 32")
    self.PartInputFrame.option_add("foreground","white")
    self.PartInputFrame.option_add("background","blue")
    self.PartInputFrame.option_add("relief","SUNKEN")



    Label(self.PartInputFrame,text="Polyline").place(rely=.3,relx=.1)
    Label(self.PartInputFrame,text='"X" Origin Set').place(rely=.35,relx=.1)
    Label(self.PartInputFrame,text='Pattern(s) Long').place(rely=.4,relx=.1)
    Label(self.PartInputFrame,text='Pattern(s) Wide').place(rely=.45,relx=.1)
    Label(self.PartInputFrame,text='Repeat Length').place(rely=.5,relx=.1)
    Label(self.PartInputFrame,text='Repeat Width').place(rely=.55,relx=.1)
    Label(self.PartInputFrame,text='Mirror (Y or N)').place(rely=.6,relx=.1)
    Label(self.PartInputFrame,text='Pattern Type').place(rely=.65,relx=.1)


    Label(self.PartInputFrame,text='Part Program').place(rely=.3,relx=.5)
    Label(self.PartInputFrame,text='Part Drawing Number').place(rely=.35,relx=.5)
    Label(self.PartInputFrame,text='Plates Produced').place(rely=.40,relx=.5)
    Label(self.PartInputFrame,text='Plates Remaining').place(rely=.45,relx=.5)
    Label(self.PartInputFrame,text='Left Setup').place(rely=.50,relx=.5)
    Label(self.PartInputFrame,text='Right Setup').place(rely=.55,relx=.5)
    Label(self.PartInputFrame,text='Plate Lenght').place(rely=.60,relx=.5)
    Label(self.PartInputFrame,text='Plate Width').place(rely=.65,relx=.5)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
133 views
Welcome To Ask or Share your Answers For Others

1 Answer

I have answered my own question. As usual it is a matter of figuring out what to search for.

self.PartInputFrame.option_add("*Font","arial 32")
self.PartInputFrame.option_add("foreground","white")
self.PartInputFrame.option_add("background","blue")
self.PartInputFrame.option_add("relief","SUNKEN")

option_add is looking for a path to the option. Not the option itself. Where I set the Font, I placed a wildcard in front of it (looked right at it but never saw it). Effectively changing the Font for everything.

Where I set the 'foreground' I did not create a path.

The correct code:

self.PartInputFrame.option_add("*Font","arial 32")
self.PartInputFrame.option_add("*foreground","white")
self.PartInputFrame.option_add("*background","blue")
self.PartInputFrame.option_add("*relief","SUNKEN")

This will change foreground,background, etc, globally.

The (more) correct code:

self.PartInputFrame.option_add("*Label.Font","arial 32")
self.PartInputFrame.option_add("*Label.foreground","white")
self.PartInputFrame.option_add("*Label.background","blue")
self.PartInputFrame.option_add("*Label.relief","SUNKEN")

will change defaults for Labels (globally) ( still do not quite understand the path before *Label. When I figure that out I will amend this answer)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...