Python Tkinter Simple Qn
Hi i have the following problem with Python Tkinter. I switch to switch the image background (which i used Tkinter.Label with image arg to display on the GUI). How can I do that? the callback function which i have created doesn't seem to work... some advice? below is my code: import Tkinter as tk from PIL import Image, ImageTk root = tk.Tk() # having problem with switching the image def callback(event): global root root.panel1.pack_forget() root.panel1.image = image2 root.panel1.pack() def app(): root.title('FIT 2022 Assignment 1') # pick an image file you have .bmp .jpg .gif. .png # load the file and covert it to a Tkinter image object imageFile = "c:\\test1.jpg" image1 = ImageTk.PhotoImage(Image.open(imageFile)) imageFile2 = "c:\\test2.jpg" image2 = ImageTk.PhotoImage(Image.open(imageFile2)) # get the image size w = image1.width() h = image1.height() # position coordinates of root 'upper left corner' x = 0 y = 0 # make the root window the size of the image root.geometry("%dx%d+%d+%d" % (w, h, x, y)) # root has no image argument, so use a label as a panel panel1 = tk.Label(root, image=image1) panel1.pack(side='top', fill='both', expand='yes') panel1.image = image1 panel1.bind("", callback) panel1.pack() root.mainloop() app() -- http://mail.python.org/mailman/listinfo/python-list
Simple Problem but tough for me if i want it in linear time
dataList = [a, b, c, ...] where a, b, c are objects of a Class X. In Class X, it contains self.name and self.number If i wish to test whether a number (let's say 100) appears in one of the object, and return that object, is that only fast way of solving this problem without iterating through every object to see the number value? dataList.__contains__ can only check my object instance name... anyone can solve this in linear complexity? -- http://mail.python.org/mailman/listinfo/python-list
2 threads; 1 more Tkinter and 1 more terminal. problem
Hi all, i am trying to do a GUI with Tkinter package, but i am stuck no matter what... The problem right now is that my GUI has a label= 'A' (where 'A' is the text on display) i wish to run a program with 2 threads... one for my GUI and the other for the terminal where the terminal will keep listening to the user input (let's say if he enters 'B'), the GUI will update it's label to 'B'. It's easy to let the terminal wait after the user has entered the input. But the problem is that when the GUI loads up... the root.mainloop() doesn't seem to release the control, hence my thread cannot work on GUI. Is there a way to solve this problem? 2 threads; 1 more GUI and 1 more terminal. -- http://mail.python.org/mailman/listinfo/python-list
Re: 2 threads; 1 more Tkinter and 1 more terminal. problem
On Aug 16, 4:17 am, Terry Reedy wrote: > On 8/15/2010 10:22 AM, ChrisChia wrote: > > > Hi all, > > i am trying to do a GUI with Tkinter package, but i am stuck no matter > > what... > > The problem right now is that my GUI has a label= 'A' (where 'A' is > > the text on display) > > > i wish to run a program with 2 threads... one for my GUI and the other > > for the terminal where the terminal will keep listening to the user > > input (let's say if he enters 'B'), the GUI will update it's label to > > 'B'. > > Makes no sense to me. GUI = graphics user interface. Interface = input > from and output to the user. Additional threads for for other activities > that may block or be compute intensive, not a separate text user interface. > > > It's easy to let the terminal wait after the user has entered the > > input. > > But the problem is that when the GUI loads up... the > > > root.mainloop() > > > doesn't seem to release the control, > > That seems to be the point of a GUI > > -- > Terry Jan Reedy The idea has is that the interface acts as a window to display the text type from the terminal. It's a crazy idea but i wish to implement something that way. The GUI in the case will display any text that the user enters from the terminal... Any idea to make both the processes running and listening at the same time? -- http://mail.python.org/mailman/listinfo/python-list
how to switch image in tkinter? making it mutable? how?
I have this: image1 = ImageTk.PhotoImage(file = "c:\\f1.jpg") image2 = ImageTk.PhotoImage(file = "c:\\f2.jpg") imagelist.append(image1) imagelist.append(image2) self.label = tk.Label(image = imagelist[0]) is there a way that i can create a method to switch the display the image2 (imagelist 2nd element) without using label.bind? can i make an image mutable? -- http://mail.python.org/mailman/listinfo/python-list
Re: how to switch image in tkinter? making it mutable? how?
On Aug 17, 2:57 am, Jeff Hobbs wrote: > On Aug 16, 7:30 am, ChrisChia wrote: > > > I have this: > > image1 = ImageTk.PhotoImage(file = "c:\\f1.jpg") > > image2 = ImageTk.PhotoImage(file = "c:\\f2.jpg") > > > imagelist.append(image1) > > imagelist.append(image2) > > > self.label = tk.Label(image = imagelist[0]) > > > is there a way that i can create a method to switch the display the > > image2 (imagelist 2nd element) > > without using label.bind? > > > can i make an image mutable? > > self.label.configure(image = imagelist[1]) will change the image > displayed. > With PIL images, you can use image1.fromstring(...) that should have a > similar effect, in that it changes the underlying image data and the > label will display that. > > Whether you need to label.bind or something else to effect this change > is up to you. You could have it happen on a timer, triggered by an > event, or randomly effected by solar flares, depending on your > application's needs. > > Jeff Yes... I don't intend to make it mutable anymore... thanks to Jeff for the self.label.configure i don't even know about the configure method. I m very new to tkinter. Thanks everyone!!! -- http://mail.python.org/mailman/listinfo/python-list