Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Using a window style in a Toplevel window
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
craf  
View profile  
 More options Dec 3 2010, 12:04 pm
Newsgroups: comp.lang.python
From: craf <p...@vtr.net>
Date: Fri, 03 Dec 2010 14:04:27 -0300
Local: Fri, Dec 3 2010 12:04 pm
Subject: Using a window style in a Toplevel window
Hi.

I use Python 3.1 and Tkinter.ttk 8.5 on Ubuntu 9.10.

CODE:----------------------------------------------------

module:FMain.py

from tkinter import ttk
from FSecondWindow import *

class App:
    def __init__(self,master):

        button1 = ttk.Button(master,text='Show
TopLevel',command=lambda:window())
        button1.pack()

master = Tk()
app = App(master)
style = ttk.Style()
style.theme_use('clam')
master.mainloop()

module:FSecondWindow.py

from tkinter import *
from tkinter import ttk

def window():
    t = Toplevel()
    button2 = Button(t,text='Hello').pack()    

CODE EXPLANATION:-------------------------------------------

1. From the main module FMain.py call the window function that is
located in FSecondWindow module and create a toplevel window.

2.I apply a theme called 'clam' to the master window to improve the
appearance of their widgets.

QUERY:--------------------------------------------------

How I can make the toplevel window also take the theme 'clam'?

Thanks in advance.

Regards.

Cristian Abarzúa.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Eric Brunel  
View profile  
 More options Dec 9 2010, 4:00 am
Newsgroups: comp.lang.python
From: Eric Brunel <eric.bru...@pragmadev.nospam.com>
Date: Thu, 09 Dec 2010 10:00:39 +0100
Local: Thurs, Dec 9 2010 4:00 am
Subject: Re: Using a window style in a Toplevel window
In article <mailman.185.1291395907.2649.python-l...@python.org>,

Short answer: you can't. No directly anyway.

Long answer: As you might be aware, there are 2 widget sets in
tk/tkinter, the "old" one for which classes are directly in the tkinter
module, and the new one that are in the ttk submodule. Only the second
set supports theming, not the first one. Unfortunately, there are a few
widgets that exist only in the first set, and Toplevel is one of those.
So no theming is directly available for toplevels, and you can change
whatever you want via style.theme_use, it won't be reflected on
toplevels.

By the way, as you wrote the code above, it won't be reflected on your
button either, since you used the Button class, which is taken in
tkinter directly, so it is the "old" Button class, not the new one. To
get the new one, use ttk.Button, not Button.

For your toplevel, there is however a simple workaround: Since there is
a Frame widget in the new widget set, you can simply insert such a frame
in your toplevel, make sure it will take the whole space, and then
insert your widgets in this frame rather than in the toplevel directly.
The code for your 'window' function would then become:

def window()
    t = Toplevel()
    frm = ttk.Frame(t)
    frm.pack(fill=BOTH, expand=True)
    button2 = ttk.Button(frm, text='Hello')
    button2.pack()

(Note also that I have put the creation of the button and its packing in
2 lines. You should never do variable = widget.pack(…) since pack does
not return the widget. It always returns None, so doing so won't put
your widget in the variable).

The code above should do what you're after.

> Thanks in advance.

HTH
 - Eric -

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
pyt...@bdurham.com  
View profile  
 More options Dec 9 2010, 7:19 am
Newsgroups: comp.lang.python
From: pyt...@bdurham.com
Date: Thu, 09 Dec 2010 07:19:30 -0500
Local: Thurs, Dec 9 2010 7:19 am
Subject: Re: Using a window style in a Toplevel window
Eric,

Besides style support, what are the advantages of ttk.Frame vs.
Tkinter.Frame?

Thanks,
Malcolm


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Eric Brunel  
View profile  
 More options Dec 9 2010, 11:50 am
Newsgroups: comp.lang.python
From: Eric Brunel <eric.bru...@pragmadev.nospam.com>
Date: Thu, 09 Dec 2010 17:50:36 +0100
Local: Thurs, Dec 9 2010 11:50 am
Subject: Re: Using a window style in a Toplevel window
In article <mailman.346.1291897180.2649.python-l...@python.org>,

 pyt...@bdurham.com wrote:
> Eric,

> Besides style support, what are the advantages of ttk.Frame vs.
> Tkinter.Frame?

I'd say none. They are both just containers for other widgets, support
the same layout managers, and so on. For me, using a ttk.Frame is really
just for getting the correct theme, nothing else...


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »