Font issues Tkinter/Python 3.5
import tkinter as tk from tkinter import ttk from tkinter import font ... def __init__(self): self.root = tk.Tk() self.root.title('Main Window') self.root.geometry('1000x800+200+200') self.root.minsize(width=1000, height=800) default_font = tkFont.nametofont("TkDefaultFont") default_font.configure(size=12) self.root.option_add("*Font", default_font) ... self.root.mainloop() ... tells me that 'tkFont' is not defined. What am I missing? As always, thanks for any pointers! -- https://mail.python.org/mailman/listinfo/python-list
Tkinter spacing
If I want to have some space between, say, btn_last & btn_new, will I have to use a dummy label in between these two or is there a better way? Thanks for any help, as always! from tkinter import * from tkinter import ttk root = Tk() root.geometry("822x600+100+100") nav_bar = ttk.Frame(root, borderwidth=2, relief='ridge', padding=(10, 3, 10, 3)) btn_first = ttk.Button(nav_bar, text='|<', width=4) # for buttons showing text only, this will be text units (= average characters?) btn_prev = ttk.Button(nav_bar, text='<', width=4) # for image buttons, it will be in pixels btn_next = ttk.Button(nav_bar, text='>', width=4) btn_last = ttk.Button(nav_bar, text='>|', width=4) btn_new= ttk.Button(nav_bar, text='New') btn_edit = ttk.Button(nav_bar, text='Edit') btn_delete = ttk.Button(nav_bar, text='Delete') btn_cancel = ttk.Button(nav_bar, text='Cancel') btn_print = ttk.Button(nav_bar, text='Print') btn_help = ttk.Button(nav_bar, text='Help') btn_save = ttk.Button(nav_bar, text='Save') lbl_Recs = ttk.Label(nav_bar, text='Records') lbl_RCount = ttk.Label(nav_bar, text='0 ', width=10, borderwidth=2, relief='sunken', anchor='e') # fake entry look nav_bar.grid(column=0, row=0, columnspan=13) btn_first.grid(column=0, row=0) btn_prev.grid(column=1, row=0) btn_next.grid(column=2, row=0) btn_last.grid(column=3, row=0) btn_new.grid(column=4,row=0) btn_edit.grid(column=5, row=0) btn_delete.grid(column=6, row=0) btn_cancel.grid(column=7, row=0) lbl_Recs.grid(column=8, row=0, padx=5) lbl_RCount.grid(column=9, row=0, padx=5) btn_print.grid(column=10, row=0) btn_help.grid(column=11, row=0) btn_save.grid(column=12, row=0) root.mainloop() -- https://mail.python.org/mailman/listinfo/python-list
Re: tkinter newbie question
On Sunday, 24 January 2016 20:20:07 UTC-8, KP wrote: > See my code below (which works). 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! > > > > > #!/usr/bin/env python > """ > """ > from tkinter import * > from settings import * > > class window1(): > > def open_window2(self): > t = Toplevel(self.root) > t.title('New window') > t.geometry('262x65+200+250') > t.transient(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() Thank you - much appreciated! -- https://mail.python.org/mailman/listinfo/python-list
Re: tkinter newbie question
On Monday, 25 January 2016 08:22:12 UTC-8, KP wrote: > On Monday, 25 January 2016 00:51:34 UTC-8, Peter Otten wrote: > > 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() > > Dang - almost there. Using your code, I get the new window with the specified > geometry and its type is transient, as expected. > > Its caption, however, is NOT the caption specified, but the caption of the > first window, leaving me with 2 windows with identical caption. > > Any idea why? Forget that post - mea culpa - figured it out - sorry! -- https://mail.python.org/mailman/listinfo/python-list
Re: tkinter newbie question
On Monday, 25 January 2016 00:51:34 UTC-8, Peter Otten wrote: > 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() Dang - almost there. Using your code, I get the new window with the specified geometry and its type is transient, as expected. Its caption, however, is NOT the caption specified, but the caption of the first window, leaving me with 2 windows with identical caption. Any idea why? -- https://mail.python.org/mailman/listinfo/python-list
tkinter newbie question
See my code below (which works). 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! #!/usr/bin/env python """ """ from tkinter import * from settings import * class window1(): def open_window2(self): t = Toplevel(self.root) t.title('New window') t.geometry('262x65+200+250') t.transient(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() -- https://mail.python.org/mailman/listinfo/python-list
Re: Fast pythonic way to process a huge integer list
On Wednesday, 6 January 2016 18:37:22 UTC-8, high5s...@gmail.com wrote: > I have a list of 163.840 integers. What is a fast & pythonic way to process > this list in 1,280 chunks of 128 integers? Thanks all for your valuable input - much appreciated! -- https://mail.python.org/mailman/listinfo/python-list
Is there an idiom for this?
Given: cfg = {'c': ('3840', '1024'), 'p1': {'gpio': '1', 'id': '4', 'coord': ('0', '0', '1280', '1024')}, 'p2': {'gpio': '2', 'id': '5', 'coord': ('1280', '0', '2560', '1024')}, 'p3': {'gpio': '3', 'id': '6', 'coord': ('2560', '0', '3840', '1024')}} for config in cfg: if config != 'c': print config Is there an idiom that combines the 'for...' & the 'if..' lines into one? -- https://mail.python.org/mailman/listinfo/python-list
Idiom for this case?
Given: cfg = {'c': ('3840', '1024'), 'p1': {'gpio': '1', 'id': '4', 'coord': ('0', '0', '1280', '1024')}, 'p2': {'gpio': '2', 'id': '5', 'coord': ('1280', '0', '2560', '1024')}, 'p3': {'gpio': '3', 'id': '6', 'coord': ('2560', '0', '3840', '1024')}} for config in cfg: if config != 'canvas': print config Is there an idiom that combines the 'for...' & the 'if..' lines into one? -- https://mail.python.org/mailman/listinfo/python-list
Re: Is there an idiom for this?
Thanks Paul, you just pointed out one of my blonder moments: I actually want all nested dicts one by one, but not the one with the 'c' key... On Thursday, 24 December 2015 14:15:45 UTC-8, Paul Rubin wrote: > KP writes: > > for config in cfg: > > if config != 'c': > > print config > > > > Is there an idiom that combines the 'for...' & the 'if..' lines into one? > > Maybe you actually want > > print [config for config in cfg if config != 'c'] > > That prints all the relevant keys as a list, rather than one per line. -- https://mail.python.org/mailman/listinfo/python-list
Re: Newbie: String to Tuple
On Tuesday, 22 December 2015 12:59:59 UTC-8, Mark Lawrence wrote: > On 22/12/2015 20:53, KP wrote: > > How do I convert > > > > '1280,1024' > > > > to > > > > (1280,1024) ? > > > > Thanks for all help! > > > > Start with this https://docs.python.org/3/library/stdtypes.html#str.split > > -- > My fellow Pythonistas, ask not what our language can do for you, ask > what you can do for our language. > > Mark Lawrence Thanks - just what I was missing! -- https://mail.python.org/mailman/listinfo/python-list
Re: Newbie XML problem
Thank you both - your help is much appreciated! -- https://mail.python.org/mailman/listinfo/python-list
Newbie: Convert strings in nested dict to tuples
I now know how to convert a string cont. coordinates to a tuple, but hwo can I do this? Given cfg = {'canvas': ('3840', '1024'), 'panel1': {'gpio': '1', 'id': '4', 'co': '0,0,1280,1024'}, 'panel2': {'gpio': '2', 'id': '5', 'co': '1280,0,2560,1024'}, 'panel3': {'gpio': '3', 'id': '6', 'co': '2560,0,3840,1024'}} how can I transform cfg to cfg = {'canvas': ('3840', '1024'), 'panel1': {'gpio': '1', 'id': '4', 'co': ('0','0','1280','1024')}, 'panel2': {'gpio': '2', 'id': '5', 'co': ('1280','0','2560','1024')}, 'panel3': {'gpio': '3', 'id': '6', 'co': ('2560','0','3840','1024')}} Again, thanks for all help! -- https://mail.python.org/mailman/listinfo/python-list
Re: Newbie: Convert strings in nested dict to tuples
Beautiful - thanks! On Tuesday, 22 December 2015 15:23:25 UTC-8, Peter Otten wrote: > KP wrote: > > > I now know how to convert a string cont. coordinates to a tuple, but hwo > > can I do this? > > > > Given > > > > cfg = {'canvas': ('3840', '1024'), > > 'panel1': {'gpio': '1', 'id': '4', 'co': '0,0,1280,1024'}, > > 'panel2': {'gpio': '2', 'id': '5', 'co': '1280,0,2560,1024'}, > > 'panel3': {'gpio': '3', 'id': '6', 'co': '2560,0,3840,1024'}} > > > > how can I transform cfg to > > > > cfg = {'canvas': ('3840', '1024'), > > 'panel1': {'gpio': '1', 'id': '4', 'co': ('0','0','1280','1024')}, > > 'panel2': {'gpio': '2', 'id': '5', 'co': > > ('1280','0','2560','1024')}, 'panel3': {'gpio': '3', 'id': '6', > > 'co': ('2560','0','3840','1024')}} > > > > Again, thanks for all help! > > >>> cfg = {'canvas': ('3840', '1024'), > ... 'panel1': {'gpio': '1', 'id': '4', 'co': '0,0,1280,1024'}, > ... 'panel2': {'gpio': '2', 'id': '5', 'co': '1280,0,2560,1024'}, > ... 'panel3': {'gpio': '3', 'id': '6', 'co': '2560,0,3840,1024'}} > >>> > >>> for value in cfg.values(): > ... if isinstance(value, dict): > ... value["co"] = tuple(value["co"].split(",")) > ... > >>> import pprint > >>> pprint.pprint(cfg) > {'canvas': ('3840', '1024'), > 'panel1': {'co': ('0', '0', '1280', '1024'), 'gpio': '1', 'id': '4'}, > 'panel2': {'co': ('1280', '0', '2560', '1024'), 'gpio': '2', 'id': '5'}, > 'panel3': {'co': ('2560', '0', '3840', '1024'), 'gpio': '3', 'id': '6'}} -- https://mail.python.org/mailman/listinfo/python-list
Newbie: String to Tuple
How do I convert '1280,1024' to (1280,1024) ? Thanks for all help! -- https://mail.python.org/mailman/listinfo/python-list
Newbie XML problem
>From my first foray into XML with Python: I would like to retrieve this list from the XML upon searching for the 'config' with id attribute = 'B' config = {id: 1, canvas: (3840, 1024), comment: "a comment", {id: 4, gate: 3, (0,0, 1280, 1024)}, {id: 5, gate: 2, (1280, 0, 2560, 1024)}, {id: 6, gate: 1, (2560, 0, 3840, 1024)}} I have started to use this code - but this is beginning to feel very non-elegant; not the cool Python code I usually see... import xml.etree.ElementTree as ET tree = ET.parse('master.xml') master = tree.getroot() for config in master: if config.attrib['id'] == 'B': ... Thanks for any help! 3840,1024 "bla" 1 6 0,0,1280,1024 2 5 1280,0,2560,1024 3 4 2560,0,3840,1024 3840,1024 "a comment" 4 3 0,0,1280,1024 5 2 1280,0,2560,1024 6 1 2560,0,3840,1024 -- https://mail.python.org/mailman/listinfo/python-list
Re: List of integers
On Sunday, 13 December 2015 16:33:20 UTC-8, Chris Angelico wrote: > On Mon, Dec 14, 2015 at 11:24 AM, KP <> wrote: > > data = list(f.read(4)) > > print data > > > > from a binary file might give > > > > ['\x10', '\x20', '\x12', '\x01'] > > > > > > How can I receive this instead? > > > > [0x10, 0x20, 0x12, 0x01] > > > > Thanks for all help! > > Try this: > > data = [ord(x) for x in f.read(4)] > > Note that it won't print out in hexadecimal. > > >>> [0x10, 0x20, 0x12, 0x01] > [16, 32, 18, 1] > > If you insist on that, try a subclass of int: > > class ord(int): > ord = ord > def __new__(cls, x): > return super().__new__(cls, cls.ord(x)) > def __repr__(self): return hex(self) > > Then they'll come out in hex. > > ChrisA Thanks much! -- https://mail.python.org/mailman/listinfo/python-list
Re: Weird list conversion
On Sunday, 13 December 2015 11:57:57 UTC-8, Laura Creighton wrote: > In a message of Sun, 13 Dec 2015 11:45:19 -0800, KP writes: > >Hi all, > > > > f = open("stairs.bin", "rb") > > data = list(f.read(16)) > > print data > > > >returns > > > >['=', '\x04', '\x00', '\x05', '\x00', '\x01', '\x00', '\x00', '\x00', > >'\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00'] > > > >The first byte of the file is 0x3D according to my hex editor, so why does > >Python return '=' and not '\x3D'? > > > >As always, thanks for any help! > > 0x3d is the ascii code for '=' I am aware of that - so is the rule that non-printables are returned in hex notation whereas printables come in their ASCII representation? -- https://mail.python.org/mailman/listinfo/python-list
List of integers
data = list(f.read(4)) print data from a binary file might give ['\x10', '\x20', '\x12', '\x01'] How can I receive this instead? [0x10, 0x20, 0x12, 0x01] Thanks for all help! -- https://mail.python.org/mailman/listinfo/python-list
How to install PIL or PILLOW on OS X Yosemite?
Hi, just upgraded my Mac Mini to Yosemite and have never dabbled in Python on this OS. I see it has Python 2.7.6 installed. When I do something like from PIL import ImageFont, ImageDraw it tells me that it cannot find PIL How do I install this on Yosemite? Any pointers much appreciated KP -- https://mail.python.org/mailman/listinfo/python-list