python - Radionbutton output reset and border that's not showing up -


i coding python script can display buttons select label.

this program containing 4 radiobutton , 1 label.

so far problem of program program can not repeated. need have border surround label.

i using python 2.7 , cannot post image because don't have enough reputation

= label(the_window, text = 'null', fg = 'black',font = ('times', 36), width = 8) button.grid(row=2,column=1) button.grid(row=3,column=1) button.grid(row=2,column=2) button.grid(row=3,column=2) 

this setup

https://repl.it/bjch

you can add border label specifying relief:

direction_status = label(the_window, text = 'null', fg = 'black',                          font = ('times', 36), width = 8, relief=groove) 

rather using 4 booleanvars value attributes radio buttons, use single intvar. indicate tkinter radio buttons belong in same group, , ensure 1 can selected @ time.

from tkinter import *  # create window the_window = tk()  # give window title the_window.title('compass')  ##label widget display initial compass's status direction_status = label(the_window, text = 'null', fg = 'black',                          font = ('times', 36), width = 8)  ## function define label's text when radiobuttion being selected def update_the_window():     if v.get() == 1:         direction_status['text'] = 'nw'     if v.get() == 2:         direction_status['text'] = 'sw'     if v.get() == 3:         direction_status['text'] = 'ne'     if v.get() == 4:         direction_status['text'] = 'se'  ## label frame direction_status direction_status_frame = labelframe(the_window, relief = 'groove',                              borderwidth = 2)   v = intvar() ## 4 buttons change status sorted directions nw_button = radiobutton(text = 'north-west', variable = v,                         value= 1, command=update_the_window, padx=20) nw_button.pack(anchor=w)  sw_button = radiobutton(text = 'south-west', variable = v,                         value= 2, command = update_the_window, padx=20) sw_button.pack(anchor=w)  ne_button = radiobutton(text= 'north-east', variable = v,                         value= 3, command=update_the_window, padx=20) ne_button.pack(anchor=w)  se_button = radiobutton(text= 'south-east', variable = v,                         value= 4, command=update_the_window, padx=20) se_button.pack(anchor=w)  ## grid geometry put 4 radio buttons gui nw_button.grid(row=2,column=1) sw_button.grid(row=3,column=1) ne_button.grid(row=2,column=2) se_button.grid(row=3,column=2)  ## grid geometry manager put widget root window margin = 5 ##pixels direction_status.grid(padx=margin, pady=margin, row=1, column=1, columnspan=2)    #--------------------------------------------------------------------#  # start event loop react user inputs the_window.mainloop() 

you use stringvar instead, cuts down on size of update_the_window somewhat.

from tkinter import *  # create window the_window = tk()  # give window title the_window.title('compass')  # put code here-------------------------------------------------#  ##label widget display initial compass's status direction_status = label(the_window, text = 'null', fg = 'black',                          font = ('times', 36), width = 8)     ## function define label's text when radiobuttion being selected def update_the_window():     direction_status['text'] = direction.get()  direction = stringvar() direction.set("nw") update_the_window()  ## label frame direction_status direction_status_frame = labelframe(the_window, relief = 'groove',                              borderwidth = 2)   ## 4 buttons change status sorted directions nw_button = radiobutton(text = 'north-west', variable = direction,                         value= "nw", command=update_the_window, padx=20) nw_button.pack(anchor=w)  sw_button = radiobutton(text = 'south-west', variable = direction,                         value= "sw", command = update_the_window, padx=20) sw_button.pack(anchor=w)  ne_button = radiobutton(text= 'north-east', variable = direction,                         value= "ne", command=update_the_window, padx=20) ne_button.pack(anchor=w)  se_button = radiobutton(text= 'south-east', variable = direction,                         value= "se", command=update_the_window, padx=20) se_button.pack(anchor=w)  ## grid geometry put 4 radio buttons gui nw_button.grid(row=2,column=1) sw_button.grid(row=3,column=1) ne_button.grid(row=2,column=2) se_button.grid(row=3,column=2)  ## grid geometry manager put widget root window margin = 5 ##pixels direction_status.grid(padx=margin, pady=margin, row=1, column=1, columnspan=2)    #--------------------------------------------------------------------#  # start event loop react user inputs the_window.mainloop() 

Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -