Re: [Tutor] thinter: can't figure out how to update a window instead of creating a new on

2018-01-28 Thread Alan Gauld via Tutor
On 28/01/18 02:58, Chris Roy-Smith wrote:

> I have been playing around with the following code which I want to 
> update the window, but I creates a new window

Yes, you are creating a new window each time.
You really need to have a separate unction create the
window once and store it (or the widgets of interest)
in a variable somewhere.

Then your other functions can simply update the widgets
through the variable(s)

Remember that anything you create inside a function
gets thrown away as soon as the function exits. To make
it persist you need to move it into global storage
(or start using objects, but thats a whole other discussion)

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] thinter: can't figure out how to update a window instead of creating a new on

2018-01-28 Thread Chris Roy-Smith

Hi,

system: Python 3.6, LInux

I have been playing around with the following code which I want to 
update the window, but I creates a new window (with the correct 
display), but I have not been able to find the solution. Perhaps I'm 
using the wrong key words in my searches.


Thank you for any assistance, I'm hoping to learn something from this 
experience


Regards, Chris Roy-Smith

#!/usr/bin/python3

import mysql.connector
from tkinter import *
import pickle
master = Tk()

def getCfg():
    fobj = open('members.pkl', 'rb')
    cfg = pickle.load(fobj)
    fobj.close()
    return cfg


def editmember(page=1):
    form=Toplevel(master)
    form.title('test form')
    cfg=getCfg()
    QrySelectMembers='select ident, concat_ws(" " ,`given`, `surname`) 
as `fullname` from `details` where 1 order by `surname` asc, `given` asc 
limit '+str(page)+', 10'
    db=mysql.connector.connect(user = cfg['user'], password = 
cfg['password'], database = cfg['database'])

    cursor=db.cursor()
    cursor.execute(QrySelectMembers) #,(page))
    MemberList=list(cursor)
    cursor.close()
    db.close
    ro=0
    for Member in MemberList:
    ident=Member[0]
    msg='edit '+Member[1]
    Button(form, text=msg, command= lambda tmp=ident : 
EdForm(tmp)).grid(sticky=(W, E), row=ro, column=0)

    ro+=1
    Button(form, text='exit', command=form.destroy).grid(row=ro+1, 
column=2)
    Button(form, text='next 10', command= lambda p=page+10 : 
editmember(p)).grid(row=ro, column=1)
    Button(form, text="previous 10", command= lambda p=page-10 : 
editmember(p)).grid(row=ro, column=0)



Button(master, text='click to test', command=editmember).grid(row=0, 
column=0)

Button(master, text='quit', command=master.destroy).grid(row=1, column=0)
master.mainloop()

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor