Why my image cannot be displayed?

2016-08-12 Thread huey . y . jiang
Hi All,

Image display drives me crazy. After I get it displayed, and want to do the job 
with a class, display failed again. Please take a look at my trial code:

from Tkinter import *

class imageDisplay:
def __init__(self, parent=None):
canvas = Canvas(width=400, height=300, bg='beige')
canvas.pack()
self.canvas = canvas
img = PhotoImage(file="xxx.gif")
self.canvas.create_image(150, 0, image=img, anchor=NW)

if __name__ == '__main__':
imageDisplay()
mainloop()

Result:  A blank canvas was displayed. No error message. 

Can somebody help? Thanks so much!


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why my image cannot be displayed?

2016-08-13 Thread huey . y . jiang
On Friday, August 12, 2016 at 9:40:15 PM UTC-4, huey.y...@gmail.com wrote:
> Hi All,
> 
> Image display drives me crazy. After I get it displayed, and want to do the 
> job with a class, display failed again. Please take a look at my trial code:
> 
> from Tkinter import *
> 
> class imageDisplay:
>   def __init__(self, parent=None):
>   canvas = Canvas(width=400, height=300, bg='beige')
>   canvas.pack()
>   self.canvas = canvas
>   img = PhotoImage(file="xxx.gif")
>   self.canvas.create_image(150, 0, image=img, anchor=NW)
> 
> if __name__ == '__main__':
>   imageDisplay()
>   mainloop()
> 
> Result:  A blank canvas was displayed. No error message. 
> 
> Can somebody help? Thanks so much!

Thanks! it's working. Particularly thanks for your explanation! 
-- 
https://mail.python.org/mailman/listinfo/python-list


What is the trick between these?

2016-08-15 Thread huey . y . jiang
Hi All,


I am trapped by these two funny things:

class MyClass(upClass):

   def start(self):
   ***do_menu_here

   self.load_label_image()  # ---> this works
   self.load_canvas_image()  # ---> this does not work

   def load_label_image(self):
   img = PhotoImage(file="xx.gif")
   Label(self, image=img).pack(side=BOTTOM, expand=YES, fill=BOTH)
   return img

   def load_canvas_image(self):
   img = PhotoImage(file="xx.gif")   
   self.canvas = Canvas(self, width=500, height=300, bg='white')
   self.canvas.pack(expand=YES, fill=BOTH)
   self.canvas.create_image(50, 0, image=img, anchor=NW) 

if __name__ == '__main__':  
root = Tk()
root.mainloop()

load_label_image() works. However, I cannot do BIND with it, because img has no 
method to do binding. So, I am trying load_canvas_image. Surprise, it does not 
work. These two defs are so similar, but Python complained that no attribute of 
load_canvas_image(). It is there, coexisting with load_label_image(). 

I cannot figure out what is wrong with it, can somebody tell me why? Thanks!
-- 
https://mail.python.org/mailman/listinfo/python-list


How to make a button flashing?

2018-06-13 Thread huey . y . jiang
Hi All,

I forgot the syntax of making a button flash, and failed to find an example in 
the web. I use Tkinter, to create a button. Then made it packed, and showed up. 
Now I am trying to make button b flashing, to make it get better noticed. I 
checked the docs, and found a method flash() is available, then I tried:

b.flash()

there was no error message popped out, but there was nothing happened also. I 
wonder who can give me this help? Thanks!

Huey
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to make a button flashing?

2018-06-13 Thread huey . y . jiang
On Wednesday, June 13, 2018 at 5:23:17 PM UTC+8, huey.y...@gmail.com wrote:
> Hi All,
> 
> I forgot the syntax of making a button flash, and failed to find an example 
> in the web. I use Tkinter, to create a button. Then made it packed, and 
> showed up. Now I am trying to make button b flashing, to make it get better 
> noticed. I checked the docs, and found a method flash() is available, then I 
> tried:
> 
> b.flash()
> 
> there was no error message popped out, but there was nothing happened also. I 
> wonder who can give me this help? Thanks!
> 
> Huey

Thanks, Terry, it works!
-- 
https://mail.python.org/mailman/listinfo/python-list


How to find an object existing?

2018-06-13 Thread huey . y . jiang
Hi All,

root = Tkinter.Tk()
button = Tkinter.Button(root, text="Find me")
button.pack()

I created a button, Python object. I recall I can check this object existing by 
using   winfo, such as  winfo.exists(button). However, I forgot which super 
class contains this   winfo   method.  I printed out dir(os), dir(sys), 
dir(Tkinter), but did not find this winfo method. I wonder who will be kindly 
drop down a few lines? Thanks a lot!


Huey
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Image loading problem

2016-05-21 Thread huey . y . jiang
Thanks so much! All of methods works!
-- 
https://mail.python.org/mailman/listinfo/python-list


Is it possible to draw a BUTTON?

2016-07-27 Thread huey . y . jiang
Hi Folks,

It is common to put a BUTTON on a canvas by the means of coding. However, in my 
application, I need to draw a circle on canvas, and then make this circle to 
work as if it is a button. When the circle is clicked, it triggers a new image 
to be displayed. Somebody can help? Thanks!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Is it possible to draw a BUTTON?

2016-07-27 Thread huey . y . jiang
On Wednesday, July 27, 2016 at 4:18:29 PM UTC-4, huey.y...@gmail.com wrote:
> Hi Folks,
> 
> It is common to put a BUTTON on a canvas by the means of coding. However, in 
> my application, I need to draw a circle on canvas, and then make this circle 
> to work as if it is a button. When the circle is clicked, it triggers a new 
> image to be displayed. Somebody can help? Thanks!

---> By the way, the GUI is TK.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Is it possible to draw a BUTTON?

2016-07-27 Thread huey . y . jiang
On Wednesday, July 27, 2016 at 4:18:29 PM UTC-4, huey.y...@gmail.com wrote:
> Hi Folks,
> 
> It is common to put a BUTTON on a canvas by the means of coding. However, in 
> my application, I need to draw a circle on canvas, and then make this circle 
> to work as if it is a button. When the circle is clicked, it triggers a new 
> image to be displayed. Somebody can help? Thanks!

The example works. It is smart to bind a button to a widget, I'v learned. 
Thanks so much!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Is it possible to draw a BUTTON?

2016-07-28 Thread huey . y . jiang
On Wednesday, July 27, 2016 at 10:00:47 PM UTC-4, Rick Johnson wrote:
> On Wednesday, July 27, 2016 at 7:15:20 PM UTC-5, MRAB wrote:
> > On 2016-07-28 00:13, huey.y.ji...@gmail.com wrote:
> > > On Wednesday, July 27, 2016 at 4:18:29 PM UTC-4, huey.y...@gmail.com 
> > > wrote:
> > >> Hi Folks,
> > >>
> > >> It is common to put a BUTTON on a canvas by the means of coding. 
> > >> However, in my application, I need to draw a circle on canvas, and then 
> > >> make this circle to work as if it is a button. When the circle is 
> > >> clicked, it triggers a new image to be displayed. Somebody can help? 
> > >> Thanks!
> > >  Yes, Rick's code works great. Well, could you go a little further? I 
> > > wish to pop out an image, while clicking the circle button. I mean, when 
> > > the circle button was clicked, an image is displayed. Thanks.


> > > ---> By the way, the GUI is TK.
> > >
> > Here's a simple example:
> > 
> > 
> > #! python3.5
> > # -*- coding: utf-8 -*-
> > import tkinter as tk
> > 
> > def mouse_clicked(event):
> >  dist_sq = (event.x - circle['x']) ** 2 + (event.y - circle['y']) ** 2
> > 
> >  if dist_sq <= circle['radius'] ** 2:
> >  print('Clicked inside circle')
> > 
> > root = tk.Tk()
> > 
> > canvas = tk.Canvas(root, width=400, height=200)
> > canvas.pack()
> > 
> > circle = dict(x=60, y=60, radius=20)
> > 
> > left = circle['x'] - circle['radius']
> > top = circle['y'] - circle['radius']
> > right = circle['x'] + circle['radius']
> > bottom = circle['y'] + circle['radius']
> > 
> > canvas.create_oval((left, top, right, bottom), outline='red', fill='red')
> > canvas.bind('', mouse_clicked)
> > 
> > root.mainloop()
> 
> I didn't try your code, but you can simply it by using some of the core 
> functionality provided via "canvas.tag_bind(...)"
> 
> ## START CODE ##
> import Tkinter as tk
> 
> def cb_canvasButton(event):
> print 'You clicked me using button {0}'.format(event.num)
> canvas.move('button', 10, 10) # Little extra surprise!
> 
> root = tk.Tk()
> canvas = tk.Canvas(root)
> canvas.create_oval(10,10,50,50, outline='red', fill='blue',
>tags=('button',)
>)
> canvas.tag_bind('button', '', cb_canvasButton)
> canvas.pack()
> 
> root.mainloop() 
> ## END CODE ##

-- 
https://mail.python.org/mailman/listinfo/python-list


How to run an infinite loop on Menu?

2018-12-03 Thread huey . y . jiang
Hi Folks,

I need to run an infinite loop on a Menu button, like this:

from Tkinter import *

def run_job():
i = 0
while 1:
i = i + 1
if i > 100:
break
 ...

root = Tk()
menu = Menu(root)
root.config(menu=menu)
filemenu = Menu(menu)
menu.add_cascade(label="Jobs", menu=filemenu)
filemenu.add_command(label="Run", command=run_job)
mainloop()


In fact, the def run_job has more things to do. But, it is an infinite loop in 
essence. It works. However, when the def run_job is running, the menu will be 
hang there. I have no way to stop it. Even if I raise it with Key-Interupt, the 
thing was the same: the infinite loop cannot be stopped nicely. The only way 
was to wait until the Python interpreter notice the problem, and popped out an 
error message, then I can kill the running program.

Can anybody tell me how to handle this? I wish when variable i reached 100, the 
run_job will be end, and the Menu "Run" will be free.

Thanks in advance. 

-- 
https://mail.python.org/mailman/listinfo/python-list