微调器不会出现在表格上

时间:2014-10-28 09:19:56

标签: canvas colors spinner visible

嗨,大家好,我做了个嘘声! 我做了一个微调器并填充它,然后想...我想把表格的颜色从黑色改为白色,所以我做了但是现在旋转器不在那里我不知道我做了什么!好吧,我有点做,我想我的代码在错误的地方,但我不确定正确的地方在哪里...... sooooo

from bs4 import BeautifulSoup
from urllib import request
import sys, traceback
import re
import kivy
from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.label import Label
from kivy.uix.spinner import Spinner
from kivy.base import runTouchApp
from kivy.uix.image import Image
from kivy.uix.widget import Widget
from kivy.lang import Builder
root = Builder.load_string('''
FloatLayout:
    canvas.before:
        Color:
            rgba: 1, 1, 1, 1
        Rectangle:
        # self here refers to the widget i.e FloatLayout
            pos: self.pos
            size: self.size''')
class MainApp(App):

    def build(self):

#add drop down box filled with stations
        spinner = Spinner(
# default value shown
        text='Pick a Station',
        values=('Appledore','Axminster','Bampton','Barnstaple','Bere Alston','Bideford','Bovey Tracey','Braunton','Bridgwater','Brixham','Buckfastleigh','Budleigh Salterton','Burnham on sea','Camels Head','Castle Cary','Chagford','Chard','Cheddar','Chulmleigh','Colyton','Combe Martin','Crediton','Crewkerne','Crownhill','Cullompton','Dartmouth','Dawlish','Exeter Danes Castle','Exeter Middlemoor','Exmouth','Frome','Glastonbury','Greenbank','Hartland','Hatherleigh','Holsworthy','Honiton','Ilfracombe','Ilminster','Ivybridge','Kingsbridge','Kingston','Lundy Island','Lynton','Martock','Minehead','Modbury','Moretonhampstead','Nether Stowey','Newton Abbot','North Tawton','Okehampton','Ottery St Mary','Paignton','Plympton','Plymstock','Porlock','Princetown','Salcombe','Seaton','Shepton Mallet','Sidmouth','Somerton','South Molton','Street','Taunton','Tavistock','Teignmouth','Tiverton','Topsham','Torquay','Torrington','Totnes','USAR','Wellington','Wells','Williton','Wincanton','Witheridge','Wiveliscombe','Woolacombe','Yelverton','Yeovil'),
# just for positioning in our example
        size_hint=(None, None),
        size=(100, 44),
        pos_hint={'center_y': 0.8})
        def show_selected_value(spinner, text):
            print('The spinner', spinner, 'have text', text)
            spinner.bind(text=show_selected_value)
            runTouchApp(spinner)
        return root
###########################
#load stations into a list
StationsString = "Appledore,Axminster,Bampton,Barnstaple,Bere Alston,Bideford,Bovey Tracey,Braunton,Bridgwater,Brixham,Buckfastleigh,Budleigh Salterton,Burnham on sea,Camels Head,Castle Cary,Chagford,Chard,Cheddar,Chulmleigh,Colyton,Combe Martin,Crediton,Crewkerne,Crownhill,Cullompton,Dartmouth,Dawlish,Exeter Danes Castle,Exeter Middlemoor,Exmouth,Frome,Glastonbury,Greenbank,Hartland,Hatherleigh,Holsworthy,Honiton,Ilfracombe,Ilminster,Ivybridge,Kingsbridge,Kingston,Lundy Island,Lynton,Martock,Minehead,Modbury,Moretonhampstead,Nether Stowey,Newton Abbot,North Tawton,Okehampton,Ottery St Mary,Paignton,Plympton,Plymstock,Porlock,Princetown,Salcombe,Seaton,Shepton Mallet,Sidmouth,Somerton,South Molton,Street,Taunton,Tavistock,Teignmouth,Tiverton,Topsham,Torquay,Torrington,Totnes,USAR,Wellington,Wells,Williton,Wincanton,Witheridge,Wiveliscombe,Woolacombe,Yelverton,Yeovil"
TheStation = StationsString.split(',')

if __name__ == '__main__':
    MainApp().run()



###########################
#get info for incident
def FindIncident( sStation ):
    webpage = request.urlopen("http://www.dsfire.gov.uk/News/Newsdesk/IncidentsPast7days.cfm?siteCategoryId=3&T1ID=26&T2ID=35")#main page
    soup = BeautifulSoup(webpage)
    incidents = soup.find(id="CollapsiblePanel1") #gets todays incidents panel
    Links = [] #create list call Links

    for line in incidents.find_all('a'): #get all hyperlinks
        Links.append("http://www.dsfire.gov.uk/News/Newsdesk/"+line.get('href')) #loads links into Links list while making them full links
    n = 0
    e = len(Links)
    if e == n: #if no links available no need to continue
       print("No Incidents Found Please Try Later")
       sys.exit(0)

    sFound = False
    while n < e: #loop through links to find station
        if sFound: #if the station has been found stop looking
            sys.exit(0)
        webpage = request.urlopen(Links[n]) #opens link in list)
        soup = BeautifulSoup(webpage) #loads webpage
        if soup.find_all('p', text=re.compile(r'{}'.format(sStation))) == []:#check if returned value is found
            #do nothing leaving blank gave error
            a = "1" #this is pointless but stops the error
        else:
            print(soup.find_all('p', text=re.compile(r'{}'.format(sStation)))) #output result
            WebLink = Links[n]
            sFound = True # to avoid un needed goes through the loop process
         n=n+1 # moves counter to next in list
    if not sFound: #after looping process if nothing has been found output nothing found
        print("nothing found please try again later")
    return;
###########################

到目前为止整个事情,我要在微调器下面调用一个按钮,调用FindIncident并在微调器中选择该工作站,按钮下方将是一个标签,用于发送te细节(而不是print) 并且我希望在其下有另一个按钮,只有在找到该工作站才能打开网页中的网址时才会出现。

多数民众赞成要清楚大声笑我的问题是我在哪里可以看到微调器的代码可见?

由于 RAIF

1 个答案:

答案 0 :(得分:0)

我从头开始在表单上,​​没有意识到你必须将小部件添加到父窗口小部件

class DSFRSapp(App):
    def build(self):
        self.root = FloatLayout()
        i = Image(source='DSFRSLogo.png',
                  allow_stretch=True,
                  pos_hint = ({'center_x':0.5, 'y': .25}))
        spinner = Spinner(
text='Pick a Station',
values=('Appledore','Axminster','Bampton','Barnstaple','Bere Alston','Bideford','Bovey Tracey','Braunton','Bridgwater','Brixham','Buckfastleigh','Budleigh Salterton','Burnham on sea','Camels Head','Castle Cary','Chagford','Chard','Cheddar','Chulmleigh','Colyton','Combe Martin','Crediton','Crewkerne','Crownhill','Cullompton','Dartmouth','Dawlish','Exeter Danes Castle','Exeter Middlemoor','Exmouth','Frome','Glastonbury','Greenbank','Hartland','Hatherleigh','Holsworthy','Honiton','Ilfracombe','Ilminster','Ivybridge','Kingsbridge','Kingston','Lundy Island','Lynton','Martock','Minehead','Modbury','Moretonhampstead','Nether Stowey','Newton Abbot','North Tawton','Okehampton','Ottery St Mary','Paignton','Plympton','Plymstock','Porlock','Princetown','Salcombe','Seaton','Shepton Mallet','Sidmouth','Somerton','South Molton','Street','Taunton','Tavistock','Teignmouth','Tiverton','Topsham','Torquay','Torrington','Totnes','USAR','Wellington','Wells','Williton','Wincanton','Witheridge','Wiveliscombe','Woolacombe','Yelverton','Yeovil'),
size_hint=(None, None),
size=(150, 44),
pos_hint = ({'center_x':0.5, 'y': 0.35}))
        b = Button(text="Search For Incidents",size_hint=(None, None),
                   pos_hint =({'center_x':0.5, 'y': 0.25}),
                   size=(150, 44))
        LblRes = Label(text="Results will display here",
                       pos_hint =({'center_x':0.5, 'y': 0.15}),
                       size_hint=(600,100),color=(1,1,1,1),font_size=35)
        b.bind(on_press=FindIncident(Spinner.text))
        self.root.add_widget(spinner)
        self.root.add_widget(LblRes)
        self.root.add_widget(i)
        self.root.add_widget(b)
        return