Monday, 15 April 2013

python - tkinter gets extra blank gui and no mouse event over image -



python - tkinter gets extra blank gui and no mouse event over image -

i have coding output coordinates(row , column) in gui nowadays anywhwere when double clicked.

problem:

1.i wanted background image,if wanted know coordinates on background image ,even after double click not getting result.

2.it produces 2 gui,where 1 gives original gui , little blank gui,which havenot asked for.i need first tkinter window not second

from tkinter import * import tkmessagebox import tkinter import tkinter tki import tkfiledialog th1 class app(object): def __init__(self,root): self.root = root # create frame text , scrollbar txt_frm = tki.frame(self.root, width=900, height=900) txt_frm.pack(fill="both", expand=true) # ensure consistent gui size txt_frm.grid_propagate(false) # create first text label, widget , scrollbar self.lbl1 = tki.label(txt_frm, text="type") self.lbl1.grid(row=0,column=0,padx=2,pady=2) self.txt1 = tki.text(txt_frm, borderwidth=3, relief="sunken", height=4,width=55) self.txt1.config(font=("consolas", 12), undo=true, wrap='word') self.txt1.grid(row=25, column=7, sticky="nsew", padx=2, pady=2) scrollb1 = tki.scrollbar(txt_frm, command=self.txt1.yview) scrollb1.grid(row=25, column=7, sticky='nsew') self.txt1['yscrollcommand'] = scrollb1.set button = tki.button(txt_frm,text="click after text", command = self.retrieve_input) button.grid(column=7,row=27) button1 = tki.button(txt_frm,text="clear", command = self.clearbox) button1.grid(column=7,row=28) self.image = tkinter.photoimage(file='linux.gif') image1 = tkinter.label(txt_frm, image=self.image).grid() def clicked(event): n=100 print "the user clicked @ coordinates", event.x/n, event.y/n a='row=%s,column=%s'%(event.x/n, event.y/n) txt_frm.bind("<double-button-1>", clicked) def retrieve_input(self): input1 = self.txt1.get("0.0",'end-1c') open('textme.txt','a+') f: f.write(input1+'\n') f.close() def clearbox(self): self.txt1.delete('1.0', 'end')#<-0.0/1.0 def file_save(): f = th1.asksaveasfile(mode='w', defaultextension=".txt") filename = f.name homecoming filename root = tki.tk() menubar=menu(root) root.configure(menu=menubar) filemenu=menu(menubar,tearoff=0) menubar.add_cascade(label="file", menu=filemenu) filemenu.add_command(label="save", command=file_save) app = app(root) root.mainloop()

please mention mistakes on coding.

the problem you're binding double click event txt_frm (which bad name btw, utilize total name instead) instead of root, want method clicked called whenever double click performed. alter 1 line to

self.root.bind("<double-button-1>", clicked)

if want utilize image background, see this question

python events tkinter

No comments:

Post a Comment