[issue33289] tkinter askcolor returning floats for r, g, b values instead of ints
Bryan Oakley added the comment: yes, this is a well known backwards incompatibility. In python 2, the division operator returns an integer if both operands are integers. In python 3 it returns a float. https://www.python.org/dev/peps/pep-0238/ On Thu, Jul 12, 2018 at 8:48 AM STINNER Victor wrote: > > STINNER Victor added the comment: > > Is this issue a regression of Python 3? red/256 gave an integer on Python > 2? > > -- > nosy: +vstinner > > ___ > Python tracker > <https://bugs.python.org/issue33289> > ___ > -- title: tkinter askcolor returning floats for r,g,b values instead of ints -> tkinter askcolor returning floats for r, g, b values instead of ints ___ Python tracker <https://bugs.python.org/issue33289> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue33289] askcolor is returning floats for r, g, b values instead of ints
New submission from Bryan Oakley <bryan.oak...@gmail.com>: Even though the underlying tcl/tk interpreter is returning ints, askcolor is converting the values to floats. My guess is this is an oversight related to the change in functionality of the / operator in python3. this: return (r/256, g/256, b/256), str(result) should probably be this: return (r//256, g//256, b//256), str(result) -- components: Tkinter messages: 315367 nosy: Bryan.Oakley priority: normal severity: normal status: open title: askcolor is returning floats for r,g,b values instead of ints versions: Python 3.4, Python 3.5, Python 3.6, Python 3.7, Python 3.8 ___ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue33289> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue25684] ttk.OptionMenu radiobuttons aren't unique between two instances of OptionMenu
Changes by Bryan Oakley <bryan.oak...@gmail.com>: -- type: -> behavior ___ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue25684> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue25684] ttk.OptionMenu radiobuttons aren't unique between two instances of OptionMenu
New submission from Bryan Oakley: Original issue was brought to my attention by this SO question: http://stackoverflow.com/questions/33831289/ttk-optionmenu-displaying-check-mark-on-all-menus The ttk.OptionMenu uses radiobuttons for the dropdown menu. However, because it doesn't set the `variable` attribute, they all get the default. If you have two or more OptionMenu instances, all of the radiobuttons are tied together. If you select the first item in the first OptionMenu, and the second item in the second OptionMenu, the dropdown menu for both will show the second item checked. The solution is to add `variable=self._variable` when creating the menu radiobutton items. -- components: Tkinter messages: 255001 nosy: Bryan.Oakley priority: normal severity: normal status: open title: ttk.OptionMenu radiobuttons aren't unique between two instances of OptionMenu versions: Python 2.7, Python 3.2, Python 3.3, Python 3.4, Python 3.5, Python 3.6 ___ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue25684> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue15861] ttk.Treeview unmatched open brace in list
Bryan Oakley added the comment: I gave myself an hour or so to play around with this, and the crux of the matter seems to be in the function `_format_optdict()` which converts a dictionary of options and values into something suitable to pass to `tk.call()`. However, I think the same bug is in other `_format*` functions as well, it's just that their nature is such that they have much less of a chance to be passed weird data. `_format_optdict` has some code that does a half-hearted attempt at handling values that are tuples, such as the case with the values attribute of the ttk.Treeview widget. However, all it does is protect values that have a space, by surrounding the value with curly braces. Hence, when the value itself has a curly brace, tcl throws the unmatched open brace error. What is needed is to create a bona fide tcl list element according to the rules of Tcl. I tried a hack where I simply escaped all problem characters, so instead of returning `{foo bar}` the function returns `foo\ bar`. This seemed to work, at least for the tiny bit of testing that I did. Another solution might be to do something like tk.call(list,*the_tuple), though sadly, `_format_optdict` is a function rather than a method so it doesn't have access to the tcl interpreter. What I think ttk needs (and may already exist somewhere in the Tkinter world; I haven't looked...) is a function that takes a tuple and converts it to a canonical list. Then, the places that do something ad hoc can all call this one function. For more information on the gory details of the string representation of a list see http://www.tcl.tk/cgi-bin/tct/tip/407.html -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue15861 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue15861] ttk.Treeview unmatched open brace in list
Bryan Oakley added the comment: What behavior do I expect? I expect it to not throw an error. I expect whatever string I give to be inserted into the widget unadulterated (ie: if I give the string foo { I expect to see foo { in the widget). Tkinter is effectively telling me you have a Tcl syntax error. Since I'm programming in python I should be insulated from that, particularly since the error comes internally after Tkinter transforms my data. How Tkinter does it under the hood, I don't care. Tkinter should make sure that the data it passes to the Tcl interpreter is well-formed. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue15861 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue15861] ttk.Treeview unmatched open brace in list
New submission from Bryan Oakley: If you try to insert an item into the treeview, give it a tuple of values for the values attribute, and one of those values has unbalanced braces, you'll get an error unmatched open brace in list To reproduce: import Tkinter as tk import ttk root = tk.Tk() tree = ttk.Treeview(root) tree.insert(,end,values=(one,two,bam! {)) root.mainloop() -- components: Tkinter messages: 169839 nosy: Bryan.Oakley priority: normal severity: normal status: open title: ttk.Treeview unmatched open brace in list type: behavior versions: Python 2.7 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue15861 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
Re: tkinter, canvas, get color of image?
[EMAIL PROTECTED] wrote: On 13 Apr, 19:19, Bryan Oakley [EMAIL PROTECTED] wrote: [EMAIL PROTECTED] wrote: mapq = PhotoImage(file = 'C:\Users\saftarn\Desktop\elmapovic.gif') w.create_image(10, 10, image = mapq, anchor = NW) after doing this is there any possibility of getting the characteristics of the GIF-picture(or bitmap if i use that)? it would be very helpfull if i for example could do something like canvas.getcolor(image, mouseclick.x,mouseclick.y) if u get the point. get the color of the image where i clicked. The image isn't painted on the canvas, so to answer your specific question, no, you can't get the color of a pixel on the canvas in the way that you ask. However, when you click on the canvas you can get the item that was clicked on and the x/y of the click. From that you can figure out which pixel of the image is under the cursor. And from that you can query the image for the color of a specific pixel. how do i get the item? http://effbot.org/tkinterbook/canvas.htm#Tkinter.Canvas.create_image-method with any of those methods? when i click the mouse i can get event.object u mean? You can use find_closest to find the object closest to the x,y of the event. You can also do find_withtag(tk.CURRENT) which returns the item under the mouse pointer. -- http://mail.python.org/mailman/listinfo/python-list
Re: tkinter, annoying grid-problem
[EMAIL PROTECTED] wrote: so my little calculator works perfectly now. just having some trouble with the layout. this whole tkinter-thing seems to be more tricky than it should be. how can i make the 4 column of buttons have the same distance and size between them as the other 3 columns? and how can i make the top entry end where the 2nd row entry ends(meaning the top entry will be longer)? why are the 4th row split from the others? hard to fix the problems when u dont even understand why things happen. seems so llogical a lot of it. i change something then something unexpected happens. The best answer I can give (being a Tk expert but not yet a tkinter expert) is to start with a piece of graph paper. Draw the GUI out and you'll probably see what the problems are. For one, the second entry (for the answer) spans 4 columns and begins at column 3, so it ends up in column 6. This ends up affecting the whole layout because nothing else goes to column six. You'll probably find it much easier going to break down your GUI into sections. One for the calculator buttons and one for everything else. Create a frame for the buttons and it becomes trivial to layout out all the buttons in a 4x6 grid, unaffected by things outside that grid. Then, create your other widgets and grid the whole frame of buttons as a single unit inside the outermost frame. I quite often use grid for interior groupings, then use pack on the outter-most frame to manager the various groups. Using the grid layout manager is trivial if you do a little thinking and planning up front. If you don't, you can spend all day chasing down why you end up with an extra blank row or column, unusually sized rows and columns, etc. Again, get a piece of graph paper and draw it out -- that helps immensely when you're first coming up to speed using grid. -- http://mail.python.org/mailman/listinfo/python-list
Re: Looking for a way to include Pyhtho scripting INSIDE a python program
Ivan Illarionov wrote: You don't need to envoke another interpreter. Python can interpret arbitrary python code with exec statement. Wrap user's string inside function definition, and exec it. You might want to disable words like `import`, `exec` and `eval` in user's code because it's a big security risk. The above statement is exactly why one would want to eval the code inside a separate interpreter. Not just for security, but to prevent user code from stomping all over the application code by creating or destroying global resources. Is it possible to create a nested interpreter like you can do in some other languages? -- http://mail.python.org/mailman/listinfo/python-list
Re: tkinter, canvas, get color of image?
[EMAIL PROTECTED] wrote: mapq = PhotoImage(file = 'C:\Users\saftarn\Desktop\elmapovic.gif') w.create_image(10, 10, image = mapq, anchor = NW) after doing this is there any possibility of getting the characteristics of the GIF-picture(or bitmap if i use that)? it would be very helpfull if i for example could do something like canvas.getcolor(image, mouseclick.x,mouseclick.y) if u get the point. get the color of the image where i clicked. The image isn't painted on the canvas, so to answer your specific question, no, you can't get the color of a pixel on the canvas in the way that you ask. However, when you click on the canvas you can get the item that was clicked on and the x/y of the click. From that you can figure out which pixel of the image is under the cursor. And from that you can query the image for the color of a specific pixel. -- http://mail.python.org/mailman/listinfo/python-list
Re: tkinter, overwrite Label-text?
[EMAIL PROTECTED] wrote: ok but i have trouble using grid. if i try to use a Label witht he text answer in the following code it doenst work very well. Can you describe have trouble? What sort of trouble -- syntax errors, the text never shows up, etc? Following is my attempt to use a label and textvariables for both the label widget and the entry widget. Caveat emptor: I've *never* written a tkinter program before in my life. I'm a tcl/tk expert but I'm learning python and this is my very first attempt. I took the liberty to reorganize the code slightly. There are still resize behaviors I don't like but let's tackle one problem at a time (rest assured: the problems are all solvable). Does this do what you want? from __future__ import division import Tkinter from Tkinter import * def main(): root = Tkinter.Tk() makeUI(root) root.mainloop() exit() def makeUI(root): global entryVariable global displayVariable displayVariable = StringVar() entryVariable = StringVar() root.title(Calculator) entry = Entry(root, textvariable=entryVariable) entry.grid(row=1, column=1, columnspan=4, sticky=nsew) display=Label(root, textvariable=displayVariable) display.grid(row=2, column=1, columnspan=4, stick=nsew) x = 1 y = 4 for char in '123+456-789*0()/.': b = Button(root, text=char, command=lambda n=char:Disp(n), width=2, height=1) b.grid(row=y, column=x) x=x+1 if x==5: x=1 y=y+1 b = Button(root, text=^, command=lambda n=**:Disp(n), width=2,height=1) b.grid(row=8, column=2) b = Button(root, text=C,command=Erase, width=2, height=1) b.grid(row=8, column=3) b = Button(root, text=c,command=Backspace, width=2, height=1) b.grid(row=8, column=4) b = Button(root, text==,command=Calc, width=18, height=1) b.grid(row=9, column=1, columnspan=8) def Disp(nstr): global entryVariable tmp=entryVariable.get() tmp+=nstr entryVariable.set(tmp) def Calc(): global entryVariable global displayVariable expr=entryVariable.get() displayVariable.set() try: displayVariable.set(eval(expr)) except: displayVariable.set(Not computable) def Erase(): global entryVariable global displayVariable entryVariable.set() displayVariable.set() def Backspace(): global entryVariable tmp=entryVariable.get() tmp=tmp[0:-1] entryVariable.set(tmp) main() -- http://mail.python.org/mailman/listinfo/python-list