[Tutor] How to display radiobutton window with no buttons selected?

2017-04-24 Thread boB Stepp
Win7-64bit, Python 3.6.1

When I run the following code, the radiobutton window initially
displays with *all* buttons apparently selected.  However, when the
"Status" button is clicked on, the status is as expected, an empty
string for the checked_radiobutton StringVar().


#!/usr/bin/env python3

import tkinter as tk

root = tk.Tk()

# Report option selected:
def status():
print('You selected the radiobutton:  %s' % checked_radiobutton.get())
print()

languages = ('Perl', 'JavaScript', 'PHP', 'Python 2', 'Python 3')

# Create new variable object to keep track of checked radiobutton:
checked_radiobutton = tk.StringVar()

for language in languages:
# Create new radiobutton:
tk.Radiobutton(root, text=language, variable=checked_radiobutton,
value=language).pack(anchor='w')

checked_radiobutton.set('')

tk.Button(root, text='Status', command=status).pack(fill='x')

root.mainloop()


I wish the displayed window to initially display with no button
selected.  What am I missing here?

Thanks!

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


Re: [Tutor] Tkinter layout question

2017-04-24 Thread Phil
On Mon, 24 Apr 2017 20:02:32 +0100
Alan Gauld via Tutor  wrote:

> On 24/04/17 01:50, Phil wrote:
> > On Mon, 24 Apr 2017 09:24:55 +1000
> > Phil  wrote:
> >
> >> On Sun, 23 Apr 2017 09:39:54 +0200
> >> Sibylle Koczian  wrote:
> >>
> >>> Am 20.04.2017 um 14:43 schrieb Alan Gauld via Tutor:
>  Its not too bad you can map the large 9x9 table to the smaller
>  units using divmod()
> 
>  So the 7th element becomes
>  divmod(7) -> 2,1
> 
> >>>
> >>> Should be divmod(7, 3), shouldn't it?
> 
> Yes, of course, sorry about that!
> The 3 of course is the number of items per cell (3x3)
> 
> > Say I want the 7th cell in the first line of a 9 x 9 grid,
>  > that would be x = 7, y = 1.
> 
> But you want it mapped to a cell/item pair...
> 
> divmod(7,3) -> 2,1
> 
> 
> The 3rd cell, 2nd item which is wrong for the item part.
> So you need to use:
> 
> 2, 1-1

Thank you Alan, problem solved. All this horsing around with adding and 
subtracting 1 had initially led to a mass of confusing code hence the posting 
of my second message on this subject. Don't bother with that message, it's 
complete nonsense.

By the way, I notice that my messages to this list, and not other's, can take 
up to four hours (sometimes longer) to appear, is that normal? I'm on a bounces 
list, is that the reason? Probably not since I'm on several bounces lists.

Anyway, enjoy your holiday.

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


Re: [Tutor] Tkinter layout question

2017-04-24 Thread Alan Gauld via Tutor

On 24/04/17 20:02, Alan Gauld via Tutor wrote:


And you could wrap that up as a pair of get/set
functions if you so wished.

def get_sudoku_grid(x,y):
   # code above
   return item

def set_sudoku_grid(x,y,value):
#code above
item = value



I should point out that to use my table code for your sudoku you need to
- remove the headings
- change the Labels to Entry widgets
- write get/set methods to access the entry data

Alan G

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


Re: [Tutor] Tkinter layout question

2017-04-24 Thread Alan Gauld via Tutor

On 24/04/17 01:50, Phil wrote:

On Mon, 24 Apr 2017 09:24:55 +1000
Phil  wrote:


On Sun, 23 Apr 2017 09:39:54 +0200
Sibylle Koczian  wrote:


Am 20.04.2017 um 14:43 schrieb Alan Gauld via Tutor:

Its not too bad you can map the large 9x9 table to the smaller
units using divmod()

So the 7th element becomes
divmod(7) -> 2,1



Should be divmod(7, 3), shouldn't it?


Yes, of course, sorry about that!
The 3 of course is the number of items per cell (3x3)


Say I want the 7th cell in the first line of a 9 x 9 grid,

> that would be x = 7, y = 1.

But you want it mapped to a cell/item pair...

divmod(7,3) -> 2,1


The 3rd cell, 2nd item which is wrong for the item part.
So you need to use:

2, 1-1

Taking item 4 in your 9x9,

divmod(4,3) -> 1,1  cell 1 item 1 so again you need
to subtract 1

So we can write

def map_dimension_to_cell(index):
cell,item = divmod(index,3)
return cell,item-1

And luckily for us that works even on exact boundaries
because cell[-1] is the last item in the cell!

Mapping columns is exactly the same.

Now the only problem is to map your notional 9x9 table 9
indexing from 1 to a Python 9x9 indexing from zero.
The easiest way is to add 1 to the input index:

def map_index_to_cell(index):
cell,item = divmod(index+1,3)
return cell,item-1

You can now pass in the x or y index from your
python 9x9 table to get the cell/item indexes
in your GUI like so:

cell_x,x = map_index_to_cell(x_index)
cell_y,y = map_index_to_cell(y_index)

cell = sudoku_grid[cell_x,cell_y]
item = cell[x,y]

All untested but I think that should work...
And you could wrap that up as a pair of get/set
functions if you so wished.

def get_sudoku_grid(x,y):
   # code above
   return item

def set_sudoku_grid(x,y,value):
#code above
item = value

Sorry for the late response, I'm on a vacation so
not checking mail that often...

HTH

Alan G

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


Re: [Tutor] classproperty: readonly and inheritance - not more needed

2017-04-24 Thread Thomas Güttler


Now the "not read-only" part:


Foo.my_prop = "whatever"
Foo.my_prop

'whatever'

You now have a string attribute, the property is lost. Methods behave the
same way and it's generally not a problem, but you should at least be aware
of this behaviour.


Yes, now I understand you. Thank you

Regards,
  Thomas Güttler


--
Thomas Guettler http://www.thomas-guettler.de/
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Tkinter layout question

2017-04-24 Thread Phil
On Sun, 23 Apr 2017 11:28:51 +0200
Peter Otten <__pete...@web.de> wrote:

> Consider the function make_a_cake(). If you use it
> 
> eat_a_piece_of(make_a_cake())
> eat_a_piece_of(make_a_cake())
> 
> that's short for
> 
> one_cake = make_a_cake()
> eat_a_piece_of(one_cake)
> 
> another_cake = make_a_cake()
> eat_a_piece_of(another_cake)
> 
> i. e. you had two pieces of cake, one piece of each of two cakes.
> 
> If you write
> 
> cake = make_a_cake()
> eat_a_piece_of(cake)
> eat_a_piece_of(cake)
> 
> you have still eaten two pieces of cake but both are taken from the
> same cake.
> 
> Likewise when you write
> 
> root = tk.Tk()
> first_table = DisplayTable(root)
> second_table = DisplayTable(root)
> 
> both tables share the same instance of the Tk class.
>  
> > Also I found that root.mainloop() isn't necessary in that the
> > result is the same with or without. Perhaps it serves some other
> > purpose?
> 
> Try running it from the command line, not in idle. In every tkinter
> program there must be a main loop to respond to events.

Thank you again Peter for taking the time to answer my question.

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