我似乎无法将我制作的这两个 python 程序结合起来:(

I can't seem to combine these two python programs I made :(

最近几天我花了很多时间编写程序。我把它写成两个独立的部分,第一个是输入参数并以在线形式提交并使用 XlsxWriter 输出一个 excel 文件的算法。

另一个是我的 GUI,带有执行算法任务的按钮。

我在将它们放在一起时遇到了很多麻烦 :( 我将它们写在单独的文件中,但我似乎无法合并它们,因为我没有 main 也让我失望,我不确定如何放一切,我不断收到 IndexErrror:列表索引超出范围。

这是第一部分(我的算法)-

__author__ = 'kennytruong'
#in this version I need to work on UI and inputs
#WHATSWRONG - the (Info)

import urllib.parse, urllib.request
#import re
import xlsxwriter
from bs4 import BeautifulSoup
import time

start_time = time.clock() #to test the program time
URL = "https://interactive.web.insurance.ca.gov/survey/survey?type=homeownerSurvey&event=HOMEOWNERS"


LOCATIONS = '''
ALAMEDA ALAMEDA
ALAMEDA BERKELEY
ALAMEDA FREMONT
ALAMEDA HAYWARD
ALAMEDA LIVERMORE
'''.strip().split('\n') #strip() basically removes whitespaces
print('Available locations to choose from:', LOCATIONS)


INSURANCE_TYPES = '''
HOMEOWNERS,CONDOMINIUM,MOBILEHOME,RENTERS,EARTHQUAKE - Single Family,EARTHQUAKE - Condominium,EARTHQUAKE - Mobilehome,EARTHQUAKE - Renters
'''.strip().split(',') #strips the whitespaces and starts a newline of the list every comma
print('Available insurance types to choose from:', INSURANCE_TYPES)


COVERAGE_AMOUNTS = '''
15000,25000,35000,50000,75000,100000,150000,200000,250000,300000,400000,500000,750000
'''.strip().split(',')
print('All options for coverage amounts:', COVERAGE_AMOUNTS)


HOME_AGE = '''
New,1-3 Years,4-6 Years,7-15 Years,16-25 Years,26-40 Years,41-70 Years
'''.strip().split(',')
print('All Home Age Options:', HOME_AGE)



def main():
    #need to take their input here
    workbook = xlsxwriter.Workbook('insurance_premiums.xlsx')
    worksheet = workbook.add_worksheet()
    worksheet2 = workbook.add_worksheet()
    worksheet.set_column('A:A', 45)
    worksheet.set_column('B:KK', 30) #sets the width of each column
    worksheet2.set_column('A:A', 45)
    worksheet2.set_column('B:KK', 30)

    cityholder = 1
    colholder = 1

    for location in LOCATIONS: #need to pass their selection into this loop
        worksheet.write(0,cityholder, location) #writes city name for sheet 1 + 2
        worksheet2.write(0, cityholder , location)
        print('Now running parameters: ', location, "HOMEOWNERS", "150000", "New")
        get_premiums(location, "HOMEOWNERS", "150000", "New", worksheet, worksheet2, colholder)
        cityholder += 1
        colholder += 1
    print('Analysis Complete!')
    workbook.close()
    print(time.clock() - start_time, "seconds") #for the time of the program



def get_premiums(location, coverage_type, coverage_amt, home_age, worksheet, worksheet2, colholder):
    formEntries = {'location':location,   #fills out the form with our values
                   'coverageType':coverage_type,
                   'coverageAmount':coverage_amt,
                   'homeAge':home_age}
    inputData = urllib.parse.urlencode(formEntries)
    inputData = inputData.encode('utf-8')
    request = urllib.request.Request(URL, inputData) #makes page request to URL and pases our encoded entries
    response = urllib.request.urlopen(request)
    responseData = response.read() #reads the output of submitting our form

    soup = BeautifulSoup(responseData, "html.parser") #create my soup object with my data
    parse_it(soup, worksheet, worksheet2, colholder)





def parse_it(pass_soup, worksheet, worksheet2, colholder):
    rows = []
    data_in_table = pass_soup.find_all('table')
    t2 = None

    for t3 in data_in_table: #need this to loop properly
        t1, t2 = t2, t3

    for row in t1.find_all('tr'):
        cols = row.find_all(['td', 'th']) #find the stuff in the individual columns of the selected row
        cols = [col.text.strip() for col in cols] #cols is a list of all our text values found in the <tr> tags
        rows.append(cols) #adds our newly found info in cols into the list called 'rows'

    data = [cols[0:3] for cols in rows] #gets first list (left side)
    data2 = [cols[4:7] for cols in rows] #data2 is the right half, data is the left half

    name_placeholder = 2
    rowholder_s1 = 1
    rowholder_s2 = 1

    for row in data: #for the column with the title
        output_name = row[0]
        worksheet.write('A' + str(name_placeholder), output_name)
        worksheet2.write('A' + str(name_placeholder), output_name)
        name_placeholder += 1

    for row in data: #SHEET 1
        worksheet.write(rowholder_s1, colholder, row[1])
        worksheet.write(0, 0, "Deductible: " + row[2])
        rowholder_s1 += 1

    for row in data2:  #SHEET 2
        worksheet2.write(rowholder_s2, colholder, row[1])
        worksheet2.write(0, 0, "Deductible: " + row[2])
        rowholder_s2 += 1






















if __name__ == "__main__": #prevents indent level 0 code from getting executed
    main()

这是我的 GUI 文件 -

__author__ = 'Kenny'
import sys
from tkinter import *
import tkinter.messagebox

def helpme():
    tkinter.messagebox.showinfo('Need help?', 'Your a fucking dumbass!!!')

def aboutus():
    tkinter.messagebox.showinfo('About', "Here at Shift Insurance, we're committed to helping you get the "
                                            "lowest rates and biggest savings, while providing high quality customer "
                                            "service and a hassle free process. Part of that commitment means creating the "
                                            "best tools possible which work around the clock to make sure that you're only getting "
                                            "the best bang for your buck!\n\nThis tool is one of many in our arsenal which we use to"
                                            " analyze regional data to make sure that you're getting the most value possible."
                                            "\n\nCopyright 2015 Shift Insurance, All Rights Reserved")

def prepare_input():
    dowestart = tkinter.messagebox.askyesno(title='Verify Parameters', message='Your input parameters are: \n\nAre you sure you want to continue?') #need function for yes
    if dowestart > 0:
        print('START THE ANALYSIS FUNCTION HERE! ')
        return

root = Tk()

root.geometry('1100x500+50+50') #makes a window 850x700px and 50px from top and 50px from left corner
root.title('Shift Insurance Premium Rate Comparison Tool')


image = PhotoImage(file='shift insurance.gif') #have to create an object for it
#^NOTE: it uses 'shift insurance.gif' for MAC... HOWTO: open file with paintbrush and save as GIF.
image_label = Label(root, image=image)
image_label.place(x=0,y=0) #places the image in the top left

title = Label(text="To begin, select one option for the type of insurance, coverage amount, and home age. An xml file containing the most\n recent information from the California Department of Insurance Homeowners Premium Survey will be created.\n Only a valid combination from the Homeowners Premium Survey will work.", font=('Arial', 12))
title.place(x=275,y=0)

help_button = Button(root, text="HELP", command=helpme, padx=10, pady=5, bg='#1488CD') #tie help button to function helpme()
help_button.place(x=300,y=65)

about_button = Button(root, text="ABOUT", command=aboutus, padx=10, pady=5, bg='#1488CD')
about_button.place(x=385,y=65)

go_button = Button(root, text="BEGIN ANALYSIS", command=prepare_input, padx=25, pady=5, bg='green')
go_button.place(x=900,y=67)

#****THE FRAME FOR THE TYPE OF INSURANCE COVERAGE**************************************************
type_frame = Frame(root, width=1100, height=100)    #make frame so easier to work with
type_frame.place(x=0, y=100)
type_description = Label(type_frame, text="Select one type of insurance from the following:")      #create a label inside type_frame for simpler placement
type_description.place(x=10, y=15) #place at these coordinates within type_frame

selected_coveragetype = StringVar()
selected_coveragetype.set("1") #sets the default to the button with value "1"
type_radio1 = Radiobutton(type_frame, text='HOMEOWNERS', value = 1, variable=selected_coveragetype).place(x=320, y=15) #each item needs its own value, but these are all for 1 variable called selected_coveragetype
type_radio2 = Radiobutton(type_frame, text='CONDOMINIUM', value = 2, variable=selected_coveragetype).place(x=460, y=15)
type_radio3 = Radiobutton(type_frame, text='MOBILEHOME', value = 3, variable=selected_coveragetype).place(x=600, y=15)
type_radio4 = Radiobutton(type_frame, text='RENTERS', value = 4, variable=selected_coveragetype).place(x=730, y=15)
type_radio5 = Radiobutton(type_frame, text='EARTHQUAKE - Single Family', value=5, variable=selected_coveragetype).place(x=830, y=15)
type_radio6 = Radiobutton(type_frame, text='EARTHQUAKE - Condominium', value=6, variable=selected_coveragetype).place(x=320, y=55)
type_radio7 = Radiobutton(type_frame, text='EARTHQUAKE - Mobilehome', value=7, variable=selected_coveragetype).place(x=545, y=55)
type_radio8 = Radiobutton(type_frame, text='EARTHQUAKE - Renters', value=8, variable=selected_coveragetype).place(x=760, y=55)
#probably need a function to put that data into the input




#*****THE FRAME FOR THE SELECTED AGE OF INSURANCE COVERAGE*****************************
age_frame = Frame(root, width=1100, height=100)
age_frame.place(x=0, y=235)
age_description = Label(age_frame, text="Select one home age from the following:\n(You may also input your own, but only\n a valid home age will work)")
age_description.place(x=10, y=15)

selected_age = StringVar()
selected_age.set("1")
age_radio1 = Radiobutton(age_frame, text='New', value=1, variable=selected_age).place(x=320, y=15)
age_radio2 = Radiobutton(age_frame, text='1-3 Years', value=2, variable=selected_age).place(x=390,y=15)
age_radio3 = Radiobutton(age_frame, text='4-6 Years', value=3, variable=selected_age).place(x=485,y=15)
age_radio4 = Radiobutton(age_frame, text='7-15 Years', value=4, variable=selected_age).place(x=580, y=15)
age_radio5 = Radiobutton(age_frame, text='16-25 Years', value=5, variable=selected_age).place(x=685,y=15)
age_radio6 = Radiobutton(age_frame, text='26-40 Years', value=6, variable=selected_age).place(x=790, y=15)
age_radio7 = Radiobutton(age_frame, text='41-70 Years', value=7, variable=selected_age).place(x=895, y=15)
custom_age_radio = Radiobutton(age_frame, text='Custom Age: ', value=8, variable=selected_age).place(x=320, y=52) #if this radio is selected, pass in age_entry1 and age_entry2
age_text = Label(age_frame, text='to').place(x=472, y=55) #just for cosmetic text
years_text = Label(age_frame, text='Years').place(x=540, y=55)

age_entry1 = StringVar()  #variable which stores their first inputted value
startage_entry = Entry(age_frame, textvariable=age_entry1, width=5)
startage_entry.place(x=430, y=55)

age_entry2 = StringVar() #variable which stores 2nd inputted value for age
endage_entry = Entry(age_frame, textvariable=age_entry2, width=5)
endage_entry.place(x=497, y=55)





#******THE FRAME FOR THE SELECTED AMOUNT OF INSURANCE COVERAGE*****************
amount_frame = Frame(root, width=1100, height=100)
amount_frame.place(x=0, y=370)

amount_description = Label(amount_frame, text="Select a coverage amount from the following:\n(It will only work if the input parameter is\nvalid, and you may also input your own.)")
amount_description.place(x=10,y=15)

selected_entry = StringVar()
selected_entry.set("1")
amount_radio1 = Radiobutton(amount_frame, text='15000', value=1, variable=selected_entry).place(x=320,y=15)
amount_radio2 = Radiobutton(amount_frame, text='25000', value=2, variable=selected_entry).place(x=400,y=15)
amount_radio3 = Radiobutton(amount_frame, text='35000', value=3, variable=selected_entry).place(x=480,y=15)
amount_radio4 = Radiobutton(amount_frame, text='50000', value=4, variable=selected_entry).place(x=560,y=15)
amount_radio5 = Radiobutton(amount_frame, text='75000', value=5, variable=selected_entry).place(x=640,y=15)
amount_radio6 = Radiobutton(amount_frame, text='100000', value=6, variable=selected_entry).place(x=720,y=15)
amount_radio7 = Radiobutton(amount_frame, text='150000', value=7, variable=selected_entry).place(x=805,y=15)
amount_radio8 = Radiobutton(amount_frame, text='200000', value=8, variable=selected_entry).place(x=890,y=15)
amount_radio9 = Radiobutton(amount_frame, text='250000', value=9, variable=selected_entry).place(x=980,y=15)
amount_radio10 = Radiobutton(amount_frame, text='300000', value=10, variable=selected_entry).place(x=320,y=55)
amount_radio11 = Radiobutton(amount_frame, text='400000', value=11, variable=selected_entry).place(x=405,y=55)
amount_radio12 = Radiobutton(amount_frame, text='500000', value=12, variable=selected_entry).place(x=490,y=55)
amount_radio13 = Radiobutton(amount_frame, text='750000', value=13, variable=selected_entry).place(x=575,y=55)
custom_amount_radio = Radiobutton(amount_frame, text='Custom Amount: ', value=14, variable=selected_entry).place(x=720,y=55)
custom_amount_text = Label(amount_frame, text='$').place(x=855, y=58)

amount_entry = StringVar()
custom_amount_entry = Entry(amount_frame, textvariable=amount_entry, width=15)
custom_amount_entry.place(x=870, y=58)







root.mainloop() #keeps it continously going.

这就是我组合它的方式:( - 有人可以帮我吗?我花了很多时间在这上面,我真的很想完成这个:( 对不起,很麻烦!

__author__ = 'Kenny'


import sys
from tkinter import *
import tkinter.messagebox
import urllib.parse, urllib.request
#import re
import xlsxwriter
from bs4 import BeautifulSoup
import time

start_time = time.clock() #to test the program time
URL = "https://interactive.web.insurance.ca.gov/survey/survey?type=homeownerSurvey&event=HOMEOWNERS"


LOCATIONS = '''
ALAMEDA ALAMEDA
ALAMEDA BERKELEY
ALAMEDA FREMONT
ALAMEDA HAYWARD
ALAMEDA LIVERMORE
'''.strip().split('\n') #strip() basically removes whitespaces
print('Available locations to choose from:', LOCATIONS)


INSURANCE_TYPES = '''
HOMEOWNERS,CONDOMINIUM,MOBILEHOME,RENTERS,EARTHQUAKE - Single Family,EARTHQUAKE - Condominium,EARTHQUAKE - Mobilehome,EARTHQUAKE - Renters
'''.strip().split(',') #strips the whitespaces and starts a newline of the list every comma
print('Available insurance types to choose from:', INSURANCE_TYPES)


COVERAGE_AMOUNTS = '''
15000,25000,35000,50000,75000,100000,150000,200000,250000,300000,400000,500000,750000
'''.strip().split(',')
print('All options for coverage amounts:', COVERAGE_AMOUNTS)


HOME_AGE = '''
New,1-3 Years,4-6 Years,7-15 Years,16-25 Years,26-40 Years,41-70 Years
'''.strip().split(',')
print('All Home Age Options:', HOME_AGE)



def get_premiums(location, coverage_type, coverage_amt, home_age, worksheet, worksheet2, colholder):
    formEntries = {'location':location,   #fills out the form with our values
                   'coverageType':coverage_type,
                   'coverageAmount':coverage_amt,
                   'homeAge':home_age}
    inputData = urllib.parse.urlencode(formEntries)
    inputData = inputData.encode('utf-8')
    request = urllib.request.Request(URL, inputData) #makes page request to URL and pases our encoded entries
    response = urllib.request.urlopen(request)
    responseData = response.read() #reads the output of submitting our form

    soup = BeautifulSoup(responseData, "html.parser") #create my soup object with my data
    parse_it(soup, worksheet, worksheet2, colholder)



def parse_it(pass_soup, worksheet, worksheet2, colholder):
    rows = []
    data_in_table = pass_soup.find_all('table')
    t2 = None

    for t3 in data_in_table: #need this to loop properly
        t1, t2 = t2, t3

    for row in t1.find_all('tr'):
        cols = row.find_all(['td', 'th']) #find the stuff in the individual columns of the selected row
        cols = [col.text.strip() for col in cols] #cols is a list of all our text values found in the <tr> tags
        rows.append(cols) #adds our newly found info in cols into the list called 'rows'

    data = [cols[0:3] for cols in rows] #gets first list (left side)
    data2 = [cols[4:7] for cols in rows] #data2 is the right half, data is the left half

    name_placeholder = 2
    rowholder_s1 = 1
    rowholder_s2 = 1

    for row in data: #for the column with the title
        output_name = row[0]
        worksheet.write('A' + str(name_placeholder), output_name)
        worksheet2.write('A' + str(name_placeholder), output_name)
        name_placeholder += 1

    for row in data: #SHEET 1
        worksheet.write(rowholder_s1, colholder, row[1])
        worksheet.write(0, 0, "Deductible: " + row[2])
        rowholder_s1 += 1

    for row in data2:  #SHEET 2
        worksheet2.write(rowholder_s2, colholder, row[1])
        worksheet2.write(0, 0, "Deductible: " + row[2])
        rowholder_s2 += 1


def helpme():
    tkinter.messagebox.showinfo('Need help?', 'Your a fucking dumbass!!!')

def aboutus():
    tkinter.messagebox.showinfo('About', "Here at Shift Insurance, we're committed to helping you get the "
                                            "lowest rates and biggest savings, while providing high quality customer "
                                            "service and a hassle free process. Part of that commitment means creating the "
                                            "best tools possible which work around the clock to make sure that you're only getting "
                                            "the best bang for your buck!\n\nThis tool is one of many in our arsenal which we use to"
                                            " analyze regional data to make sure that you're getting the most value possible."
                                            "\n\nCopyright 2015 Shift Insurance, All Rights Reserved")










def run_program(LOCATIONS, selected_coveragetype, selected_age, selected_entryamount):
    #need to take their input here
    workbook = xlsxwriter.Workbook('insurance_premiums.xlsx')
    worksheet = workbook.add_worksheet()
    worksheet2 = workbook.add_worksheet()
    worksheet.set_column('A:A', 45)
    worksheet.set_column('B:KK', 30) #sets the width of each column
    worksheet2.set_column('A:A', 45)
    worksheet2.set_column('B:KK', 30)
    cityholder = 1
    colholder = 1


    for location in LOCATIONS: #need to pass their selection into this loop
        worksheet.write(0,cityholder, location) #writes city name for sheet 1 + 2
        worksheet2.write(0, cityholder , location)
        print('Now running parameters: ', location, selected_coveragetype, selected_entryamount, selected_age)
        get_premiums(location, selected_coveragetype, selected_entryamount, selected_age, worksheet, worksheet2, colholder)
        cityholder += 1
        colholder += 1
    print('Analysis Complete!')
    workbook.close()
    print(time.clock() - start_time, "seconds") #for the time of the program








#MAIN GUI OF THE PROGRAM***********************************************************************************
root = Tk()

root.geometry('1100x500+50+50') #makes a window 850x700px and 50px from top and 50px from left corner
root.title('Shift Insurance Premium Rate Comparison Tool')

image = PhotoImage(file='shift insurance.gif') #have to create an object for it
image_label = Label(root, image=image)
image_label.place(x=0,y=0) #places the image in the top left

title = Label(text="To begin, select one option for the type of insurance, coverage amount, and home age. An xml file containing the most\n recent information from the California Department of Insurance Homeowners Premium Survey will be created.\n Only a valid combination from the Homeowners Premium Survey will work.", font=('Arial', 12))
title.place(x=275,y=0)

help_button = Button(root, text="HELP", command=helpme, padx=10, pady=5, bg='#1488CD') #tie help button to function helpme()
help_button.place(x=300,y=65)

about_button = Button(root, text="ABOUT", command=aboutus, padx=10, pady=5, bg='#1488CD')
about_button.place(x=385,y=65)


selected_coveragetype = StringVar()
selected_age = StringVar()
selected_entryamount = StringVar()



#****THE FRAME FOR THE TYPE OF INSURANCE COVERAGE**************************************************
type_frame = Frame(root, width=1100, height=100)    #make frame so easier to work with
type_frame.place(x=0, y=100)
type_description = Label(type_frame, text="Select one type of insurance from the following:")      #create a label inside type_frame for simpler placement
type_description.place(x=10, y=15) #place at these coordinates within type_frame


selected_coveragetype.set("1") #sets the default to the button with value "1"
type_radio1 = Radiobutton(type_frame, text='HOMEOWNERS', value='HOMEOWNERS', variable=selected_coveragetype).place(x=320, y=15) #each item needs its own value, but these are all for 1 variable called selected_coveragetype
type_radio2 = Radiobutton(type_frame, text='CONDOMINIUM', value='CONDOMINIUM', variable=selected_coveragetype).place(x=460, y=15)
type_radio3 = Radiobutton(type_frame, text='MOBILEHOME', value='MOBILEHOME', variable=selected_coveragetype).place(x=600, y=15)
type_radio4 = Radiobutton(type_frame, text='RENTERS', value='RENTERS', variable=selected_coveragetype).place(x=730, y=15)
type_radio5 = Radiobutton(type_frame, text='EARTHQUAKE - Single Family', value='EARTHQUAKE - Single Family', variable=selected_coveragetype).place(x=830, y=15)
type_radio6 = Radiobutton(type_frame, text='EARTHQUAKE - Condominium', value='EARTHQUAKE - Condominium', variable=selected_coveragetype).place(x=320, y=55)
type_radio7 = Radiobutton(type_frame, text='EARTHQUAKE - Mobilehome', value='EARTHQUAKE - Mobilehome', variable=selected_coveragetype).place(x=545, y=55)
type_radio8 = Radiobutton(type_frame, text='EARTHQUAKE - Renters', value='EARTHQUAKE - Renters', variable=selected_coveragetype).place(x=760, y=55)





#*****THE FRAME FOR THE SELECTED AGE OF INSURANCE COVERAGE*****************************
age_frame = Frame(root, width=1100, height=100)
age_frame.place(x=0, y=235)
age_description = Label(age_frame, text="Select one home age from the following:\n(You may also input your own, but only\n a valid home age will work)")
age_description.place(x=10, y=15)


selected_age.set("1")
age_radio1 = Radiobutton(age_frame, text='New', value='New', variable=selected_age).place(x=320, y=15)
age_radio2 = Radiobutton(age_frame, text='1-3 Years', value='1-3 Years', variable=selected_age).place(x=390,y=15)
age_radio3 = Radiobutton(age_frame, text='4-6 Years', value='4-6 Years', variable=selected_age).place(x=485,y=15)
age_radio4 = Radiobutton(age_frame, text='7-15 Years', value='7-15 Years', variable=selected_age).place(x=580, y=15)
age_radio5 = Radiobutton(age_frame, text='16-25 Years', value='16-25 Years', variable=selected_age).place(x=685,y=15)
age_radio6 = Radiobutton(age_frame, text='26-40 Years', value='26-40 Years', variable=selected_age).place(x=790, y=15)
age_radio7 = Radiobutton(age_frame, text='41-70 Years', value='41-70 Years', variable=selected_age).place(x=895, y=15)
custom_age_radio = Radiobutton(age_frame, text='Custom Age: ', value=8, variable=selected_age).place(x=320, y=52) #if this radio is selected, pass in age_entry1 and age_entry2
age_text = Label(age_frame, text='to').place(x=472, y=55) #just for cosmetic text
years_text = Label(age_frame, text='Years').place(x=540, y=55)

age_entry1 = StringVar()  #variable which stores their first inputted value
startage_entry = Entry(age_frame, textvariable=age_entry1, width=5)
startage_entry.place(x=430, y=55)

age_entry2 = StringVar() #variable which stores 2nd inputted value for age
endage_entry = Entry(age_frame, textvariable=age_entry2, width=5)
endage_entry.place(x=497, y=55)





#******THE FRAME FOR THE SELECTED AMOUNT OF INSURANCE COVERAGE*****************
amount_frame = Frame(root, width=1100, height=100)
amount_frame.place(x=0, y=370)

amount_description = Label(amount_frame, text="Select a coverage amount from the following:\n(It will only work if the input parameter is\nvalid, and you may also input your own.)")
amount_description.place(x=10,y=15)


selected_entryamount.set("1")
amount_radio1 = Radiobutton(amount_frame, text='15000', value=15000, variable=selected_entryamount).place(x=320,y=15)
amount_radio2 = Radiobutton(amount_frame, text='25000', value=25000, variable=selected_entryamount).place(x=400,y=15)
amount_radio3 = Radiobutton(amount_frame, text='35000', value=35000, variable=selected_entryamount).place(x=480,y=15)
amount_radio4 = Radiobutton(amount_frame, text='50000', value=50000, variable=selected_entryamount).place(x=560,y=15)
amount_radio5 = Radiobutton(amount_frame, text='75000', value=75000, variable=selected_entryamount).place(x=640,y=15)
amount_radio6 = Radiobutton(amount_frame, text='100000', value=100000, variable=selected_entryamount).place(x=720,y=15)
amount_radio7 = Radiobutton(amount_frame, text='150000', value=150000, variable=selected_entryamount).place(x=805,y=15)
amount_radio8 = Radiobutton(amount_frame, text='200000', value=200000, variable=selected_entryamount).place(x=890,y=15)
amount_radio9 = Radiobutton(amount_frame, text='250000', value=250000, variable=selected_entryamount).place(x=980,y=15)
amount_radio10 = Radiobutton(amount_frame, text='300000', value=300000, variable=selected_entryamount).place(x=320,y=55)
amount_radio11 = Radiobutton(amount_frame, text='400000', value=400000, variable=selected_entryamount).place(x=405,y=55)
amount_radio12 = Radiobutton(amount_frame, text='500000', value=500000, variable=selected_entryamount).place(x=490,y=55)
amount_radio13 = Radiobutton(amount_frame, text='750000', value=750000, variable=selected_entryamount).place(x=575,y=55)
custom_amount_radio = Radiobutton(amount_frame, text='Custom Amount: ', value=14, variable=selected_entryamount).place(x=720,y=55)
custom_amount_text = Label(amount_frame, text='$').place(x=855, y=58)

amount_entry = StringVar()
custom_amount_entry = Entry(amount_frame, textvariable=amount_entry, width=15)
custom_amount_entry.place(x=870, y=58)


go_button = Button(root, text="BEGIN ANALYSIS", command=run_program(LOCATIONS, selected_entryamount, selected_coveragetype, selected_age), padx=25, pady=5, bg='green')
go_button.place(x=900,y=67)


root.mainloop() #keeps it continously going.

至少部分问题出在这段代码中:

for location in LOCATIONS: #need to pass their selection into this loop
    ...
    print('Now running parameters: ', location, selected_coveragetype, selected_entryamount, selected_age)
    ...

selected_coveragetype和其他变量都是StringVar的实例,所以你需要调用一个函数来获取它们的值。例如:

    print('Now running parameters: ', location, selected_coveragetype.get(),
        selected_entryamount.get(), selected_age.get())