Python Forum
[Tkinter] Radio button help
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Radio button help
#1
Hi everyone, Python noob here, im working on an assignment that is Tkinter heavy. Basically the endstate of the program is to display a GUI that allows a user to select upcoming entertainment events from data from an imported live HTML page that displays dates and a names of events using findall to display the dates and name.(like a music concert website for example.

The program also must feature an offline mode that when selected tells the program to gather the "data" from an offline source, in my case a downloaded HTML page from a sitdown comedy club.

So to get to the point of my problem. Im having trouble figuring out how to tell the radio buttons to read from the offline source when offline is selected and read from the online source when the online button is selected.
Ive tried multiple things, using if statements and different commands and functions. But im at the point where I pull my hair out when I stare at it for too long.

In this scenario the online source is there to simulate a live HTML page but they're both downloaded pages.

Below is the code I believe is pertinent to my problem.

The error I get when I run the program now is:
Error:
Exception in Tkinter callback Traceback (most recent call last): File "C:\Users\Muzz\AppData\Local\Programs\Python\Python37-32\lib\tkinter\__init__.py", line 1705, in __call__ return self.func(*args) File "C:\Users\Muzz\Documents\Python\Assigment 2\Tkinter\ProtoAssignment2\test1.py", line 65, in comedy_pressed Comedian1 = findall('">([A-Za-z]+ [A-Za-z]+ [A-Za-z]+) @',Source) File "C:\Users\Muzz\AppData\Local\Programs\Python\Python37-32\lib\re.py", line 223, in findall return _compile(pattern, flags).findall(string) TypeError: expected string or bytes-like object
Thanks in advance to anyone who takes the time to read this and help me.

from tkinter import *
from re import *
#Make the menu
entertainment_fix=Tk()


#Give menu a name----------------------------------------------------------------------------------#
entertainment_fix.title('Entertainment Fix!')
#Give the menu a background colour
entertainment_fix['bg']='light sea green'

#Insert a picture
fixpic=PhotoImage(file='entertainment.gif')
picture=Label(entertainment_fix, image=fixpic)
picture.grid(row=0, column =1)    
   

Source = ()
# Create a Interger Value for the radio buttons
On_or_Off = IntVar()
# Define a function that when called by the offline radio button, the source HTML page changes------------#
def offline():
    if On_or_Off.get() == 1:
        
        Source = open('OfflineComedy.html').read()
        
# Define a function that when called by the online radio button, the source HTML page changes-------------#    
def online():
    if On_or_Off.get() == 2:
        Source = open('OnlineComedy.html').read()
        
                    
# Create a radio button for working offline----------------------------------------------#

work_offline_button = Radiobutton(entertainment_fix,text='Work Offline',font=('Arial',10),
                                  variable = On_or_Off, value = 1,
                                  command = offline)
work_offline_button.grid(row=0,column=0)
# Create a radio button for working offline----------------------------------------------#

work_online_button = Radiobutton(entertainment_fix,text='Work Online',font=('Arial',10),
                                  variable = On_or_Off, value = 2,
                                  command = online)
work_online_button.grid(row=0,column=2)
Reply


Messages In This Thread
Radio button help - by Muzz - Apr-27-2019, 12:44 PM
RE: Radio button help - by Yoriz - Apr-27-2019, 03:40 PM
RE: Radio button help - by Larz60+ - Apr-27-2019, 03:43 PM
RE: Radio button help - by Muzz - Apr-28-2019, 01:40 AM
RE: Radio button help - by woooee - Apr-28-2019, 07:04 AM
RE: Radio button help - by Muzz - Apr-28-2019, 07:43 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Is there a way to determine if a radio button has been selected? TWB 5 5,208 Jan-31-2023, 09:44 AM
Last Post: Vadanane
  [Tkinter] Radio Buttons Working Bassackwards gw1500se 6 2,357 Dec-07-2021, 07:13 PM
Last Post: menator01
  [Tkinter] Grid the radio buttons Joni_Engr 6 4,889 Nov-24-2021, 07:20 PM
Last Post: menator01
  Radio butto to enable/disable combo box in Tkinter cybertooth 5 5,616 Oct-09-2021, 07:30 AM
Last Post: cybertooth
  problem with radio button crook79 3 3,792 Aug-12-2021, 02:30 PM
Last Post: deanhystad
  [Tkinter] I can't get information from a radio button aquerci 2 2,798 May-20-2020, 10:31 AM
Last Post: aquerci
  [PySimpleGui] How to alter mouse click button of a standard submit button? skyerosebud 3 5,068 Jul-21-2019, 06:02 PM
Last Post: FullOfHelp
  [Tkinter] Selected radio button in push button in Tkinter prashantfunde91 1 11,879 Jun-22-2017, 05:27 PM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020