Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #102087
| Path | csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Peter Otten <__peter__@web.de> |
| Newsgroups | comp.lang.python |
| Subject | Re: tkinter newbie question |
| Date | Mon, 25 Jan 2016 09:51 +0100 |
| Organization | None |
| Lines | 59 |
| Message-ID | <mailman.215.1453711872.15297.python-list@python.org> (permalink) |
| References | <ce955291-9e43-4482-9f0c-ca3f6853b0ae@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="ISO-8859-1" |
| Content-Transfer-Encoding | 7Bit |
| X-Trace | news.uni-berlin.de CYTJFpFj82sDQ/RfiYaDCQTFJMwnvRz6ywCQRj7LGFIw== |
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; '"""': 0.05; '__name__': 0.07; 'subject:question': 0.08; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.10; 'def': 0.13; "'__main__':": 0.16; '1",': 0.16; 'lowercase': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'received:t-ipconnect.de': 0.16; 'self.root': 0.16; 'tk()': 0.16; 'uppercase': 0.16; 'wrote:': 0.16; 'settings': 0.20; 'tkinter': 0.22; 'import': 0.24; 'header:User-Agent:1': 0.26; '(which': 0.26; 'header:X-Complaints-To:1': 0.26; 'separate': 0.27; 'skip:# 10': 0.27; 'always,': 0.29; 'code': 0.30; 'help!': 0.30; 'window': 0.30; "i'd": 0.31; 'skip:s 30': 0.31; 'skip:_ 10': 0.32; 'class': 0.33; 'unit': 0.35; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'thanks': 0.37; 'received:org': 0.37; 'names': 0.38; 'skip:s 40': 0.38; 'to:addr:python.org': 0.40; 'received:de': 0.40; 'your': 0.60; 'avoid': 0.61; 'conclude': 0.84 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| X-Gmane-NNTP-Posting-Host | p57bd9a4d.dip0.t-ipconnect.de |
| User-Agent | KNode/4.13.3 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.20+ |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Xref | csiph.com comp.lang.python:102087 |
Show key headers only | View raw
KP wrote:
> See my code below (which works).
>From the import of lowercase "tkinter" I conclude you are using Python 3.
> I'd like to have the 2nd window as a
> class in a separate unit. How do I code that unit and how do I call it
> from my first unit?
>
> As always, thanks for all help!
Move the code from open_window2() into a class in settings.py, e. g.
import tkinter as tk # avoid star-import
class SettingsWindow(tk.Toplevel): # Class names start with uppercase letter
# Prefer self-explaining names
def __init__(self, root):
super().__init__(root)
self.title('New window')
self.geometry('262x65+200+250')
self.transient(root)
Then use it in your main script:
> #!/usr/bin/env python
> """
> """
> from tkinter import *
import settings
> class window1():
>
> def open_window2(self):
settings.SettingsWindow(self.root)
> def setup_menu(self):
> self.menubar = Menu(self.root)
> self.menu1 = Menu(self.menubar, tearoff=0 )
> self.menu1.add_command(label="Settings", accelerator='Ctrl+S',
> command=self.open_window2) self.menubar.add_cascade(label="Menu
> 1", menu=self.menu1) self.root.config(menu=self.menubar)
>
> def __init__(self):
> self.root = Tk()
> self.root.title('Window #1')
> self.setup_menu()
> self.root.geometry('800x600+200+200')
> #
> self.root.mainloop()
>
> if __name__ == '__main__':
>
> w1 = window1()
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
tkinter newbie question KP <kai.peters@gmail.com> - 2016-01-24 20:19 -0800
Re: tkinter newbie question Peter Otten <__peter__@web.de> - 2016-01-25 09:51 +0100
Re: tkinter newbie question KP <kai.peters@gmail.com> - 2016-01-25 08:21 -0800
Re: tkinter newbie question KP <kai.peters@gmail.com> - 2016-01-25 08:23 -0800
Re: tkinter newbie question KP <kai.peters@gmail.com> - 2016-01-25 06:14 -0800
csiph-web