473,406 Members | 2,439 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Tkinter Radio button on the second window

The code create 2 windows. 2 radiobuttons are put on the second
window. A control variable "v" is binded to the 2 widgets.
But when I run the code, I found the control variable not binded
succsessfully: The second radiobutton was not selected by default;
Click ed each button always print 1. I don't know what is wrong. So I
need help.Thanks.

from Tkinter import *

def test(event_instance):
print v.get()

window1=Tk()
window2=Tk()
v=IntVar()
v.set(1)
radiobutton1=Radiobutton(window2,variable=v,value= 0)
radiobutton2=Radiobutton(window2,variable=v,value= 1)
radiobutton1.pack()
radiobutton2.pack()
radiobutton2.bind('<Button-1>',test)
radiobutton1.bind('<Button-1>',test)
window1.mainloop()

Sep 5 '08 #1
3 2285
En Thu, 04 Sep 2008 22:01:25 -0300, Dream <go*****@gmail.comescribi�:
The code create 2 windows. 2 radiobuttons are put on the second
window. A control variable "v" is binded to the 2 widgets.
But when I run the code, I found the control variable not binded
succsessfully: The second radiobutton was not selected by default;
Click ed each button always print 1. I don't know what is wrong. So I
need help.Thanks.

from Tkinter import *
window1=Tk()
window2=Tk()
Don't create more than one root Tk instance. Weird things happen, like
this.
If you need another, separate window, use a Toplevel widget.

--
Gabriel Genellina

Sep 5 '08 #2
On Thu, Sep 4, 2008 at 10:01 PM, Dream <go*****@gmail.comwrote:
The code create 2 windows. 2 radiobuttons are put on the second
window. A control variable "v" is binded to the 2 widgets.
But when I run the code, I found the control variable not binded
succsessfully: The second radiobutton was not selected by default;
Click ed each button always print 1. I don't know what is wrong. So I
need help.Thanks.

from Tkinter import *

def test(event_instance):
print v.get()

window1=Tk()
window2=Tk()
Now you have created two Tcl interpreters, and Tkinter stores the
"default master" as the first one created, so window1 is the default
master.
v=IntVar()
Here is your variable with no master specified, meaning it will use
the default master, "window1".
v.set(1)
radiobutton1=Radiobutton(window2,variable=v,value= 0)
radiobutton2=Radiobutton(window2,variable=v,value= 1)
Now you set the master for your buttons as window2, and use a variable
that has as master window1. This is the big problem, besides the use
of two Tcl interpreters. Tkinter doesn't really try to make this
situation work, so you better not continue with it.
radiobutton1.pack()
radiobutton2.pack()
radiobutton2.bind('<Button-1>',test)
radiobutton1.bind('<Button-1>',test)
window1.mainloop()

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


--
-- Guilherme H. Polo Goncalves
Sep 5 '08 #3
Thank you very much.

Now I use "window2=Toplevel()" to create the second window, and it
works well.
Sep 5 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Rob | last post by:
My first GUI so be gentle... When I start my program I call a class that runs the initial window. While in this class if a certain button is pressed it calls a function outside the class. This...
3
by: DoubleM | last post by:
Hi, I'm running Python2.3.3c1 on Mandrake 9.1 The following code is designed to bring up a window with a button labeled "popup". Clicking on the popup buttons triggers a secondary window with...
1
by: Pekka Niiranen | last post by:
Hi there, after reading TkInter/thread -recipe: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/82965 I wondered if it was possible to avoid using threads for the following problem: ...
5
by: max(01)* | last post by:
hello. i wrote a very simple tkinter demo program that uses menus, buttons, labels, entries, frames and secondary toplevels. it is a python version of a java program made by a colleague. ...
0
by: Stewart Midwinter | last post by:
I have a Tkinter app running on cygwin. It includes a Test menu item that does nothing more than fetch a directory listing and display it in a Toplevel window (I'd use a tkMessageBox showinfo...
3
by: dwelch91 | last post by:
I'm trying unsuccessfully to do something in Tk that I though would be easy. After Googling this all day, I think I need some help. I am admittedly very novice with Tk (I started with it...
5
by: H J van Rooyen | last post by:
Hi, I am struggling to get the pack method to do what I intend. I am trying to display user input in a seperate window, along with a little description of the field, something like this: ...
1
kaarthikeyapreyan
by: kaarthikeyapreyan | last post by:
Beginners Game- Tic-Tac-Toe My first attempt after learning Tkinter from Tkinter import * import tkFont class myApp: """ Defining The Geometry of the GUI And the variables Used In the...
3
by: J-Burns | last post by:
Hello. Im a bit new to using Tkinter and im not a real pro in programming itself... :P. Need some help here. Problem 1: How do I make something appear on 2 separate windows using Tkinter? By...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.