def get_input_widget(self): """Get Input fields to login to the tealium API""" self.input_fields['account'] = widgets.Text( description="Tealium Account:", style=STYLE_TEXT_INPUT, layout=LAYOUT_TEXT_INPUT, value=self.default_input['account']) self.input_fields['profile'] = widgets.Text( description="Tealium Profile:", style=STYLE_TEXT_INPUT, layout=LAYOUT_TEXT_INPUT, value=self.default_input['profile']) self.input_fields['username'] = widgets.Text( description="Tealium User Email:", style=STYLE_TEXT_INPUT, layout=LAYOUT_TEXT_INPUT, value=self.default_input['username']) self.input_fields['key'] = widgets.Text( description="Tealium User API Key:", style=STYLE_TEXT_INPUT, layout=LAYOUT_TEXT_INPUT, value=self.default_input['key'], placeholder= 'You can find the API key in Tealium iQ - Edit/View User Settings') input_submit = widgets.Button(description='Log in', style=STYLE_BUTTON, button_style='primary') input_submit.on_click(self.action_login) return widgets.VBox(list(self.input_fields.values()) + [input_submit])
def create_extents_gui(min_date, max_date, min_lon, max_lon, min_lat, max_lat): """ Description: ----- """ # Create widgets start_date_text = widgets.Text() end_date_text = widgets.Text() min_lon_text = widgets.BoundedFloatText(min=min_lon, max=max_lon) max_lon_text = widgets.BoundedFloatText(min=min_lon, max=max_lon, value=min_lon_text.value + 1) min_lat_text = widgets.BoundedFloatText(min=min_lat, max=max_lat) max_lat_text = widgets.BoundedFloatText(min=min_lat, max=max_lat, value=min_lat_text.value + 1) # Display form display(widgets.Label('Start date: '), start_date_text) display(widgets.Label('End date: '), end_date_text) display(widgets.Label('Min lon: '), min_lon_text) display(widgets.Label('Max lon: '), max_lon_text) display(widgets.Label('Min lat: '), min_lat_text) display(widgets.Label('Max lat: '), max_lat_text) return [ start_date_text, end_date_text, min_lon_text, max_lon_text, min_lat_text, max_lat_text ]
def requestWELocation(self, rows): if self.glove_path is None or len(self.glove_path.strip()) == 0: rows += self.addSeparator() rows.append( widgets.HTML(value='<h4>Set up your Glove model</h4><p>In order to use word embedding, you need ' 'to tell where the glove model locates:</p><p>If you have not downloaded yet,' 'you can download it from <a href="https://nlp.stanford.edu/projects/glove/" ' ' target="_blank">Glove Site</a><p>. Once you download it, you need to unzip it' ' and copy the unzipped file path here. SmartAnno will automatically convert it ' 'into binary format (will be loaded faster). If you do not set it up, the word ' 'embedding synonym extender will be <b>skipped</b>.</p>')) self.glove_path_input = widgets.Text( value='', placeholder='copy and paste your glove model file location here', description='', disabled=False, layout=widgets.Layout(width='70%') ) self.glove_vocab_input = widgets.Text(value=str(self.glove_vocab), placeholder='', description='', disabled=False) self.glove_vector_input = widgets.Text(value=str(self.glove_vector), placeholder='the vector size of the glove model', description='', disabled=False) rows.append(self.glove_path_input) rows.append(widgets.HTML(value='The vocabulary size of the glove model:')) rows.append(self.glove_vocab_input) rows.append(widgets.HTML(value='The vector size of the glove model:')) rows.append(self.glove_vector_input) rows += self.addSeparator() pass
def make_form(): k1 = widgets.Text( value='Hello World', placeholder='KA', description='Keyword A', disabled=False, layout=widgets.Layout(width='50%') ) k2 = widgets.Text( value='Hello Wrld', placeholder='KB', description='Keyword B', disabled=False, layout=widgets.Layout(width='50%') ) s = widgets.IntSlider( value=70, min=20, max=80, step=1, description='% for train:', disabled=False, continuous_update=False, orientation='horizontal', readout=True, readout_format='d' ) w = widgets.VBox((k1,k2,s)) return w, k1, k2, s
def __init__(self, rm, vars=None, show_jobs=True, wide_display=True): self.rm_original = rm if vars is None: fname = os.path.join(rm.savedir_base, '.dashboard_history.json') if os.path.exists(fname): self.vars = hu.load_json(fname) else: self.vars = {} self.vars = vars self.show_jobs = show_jobs self.wide_display = wide_display self.layout=widgets.Layout(width='100px') self.layout_label=widgets.Layout(width='200px') self.layout_dropdown = widgets.Layout(width='200px') self.layout_button = widgets.Layout(width='200px') self.t_savedir_base = widgets.Text( value=str(self.vars['savedir_base']), layout=widgets.Layout(width='600px'), disabled=False ) self.t_filterby_list = widgets.Text( value=str(self.vars.get('filterby_list')), layout=widgets.Layout(width='1200px'), description=' filterby_list:', disabled=False )
def list_elements(self): retrieve_material = RetrieveMaterialMetadata(material='all') self.list_returned = retrieve_material.full_list_material() # import pprint # pprint.pprint(list_returned) box4 = widgets.HBox([ widgets.Label("List of elements", layout=widgets.Layout(width=self.label_width)), widgets.Text(','.join(self.list_of_elements), layout=widgets.Layout(width='20%')) ]) box5 = widgets.HBox([ widgets.Label("Nbr Bragg Edges", layout=widgets.Layout(width=self.label_width)), widgets.Text(str(8), layout=widgets.Layout(width='20%')) ]) vertical_box = widgets.VBox([box4, box5]) display(vertical_box) self.list_elements_ui = box4.children[1] self.nbr_bragg_edges_ui = box5.children[1]
def i_get_job_script(): from ipywidgets import widgets, Layout, interact_manual from IPython.display import display, clear_output from os.path import isfile inodes = widgets.BoundedIntText(value=1, min=1, max=4394, step=1, description='nodes', disabled=False) iranks_per_node = widgets.BoundedIntText(value=1, min=1, max=64, step=1, description='ranks/node', disabled=False) iaffinity = widgets.Text(value='-d 1 -j 1 --cc depth', description='affinity') icommand = widgets.Text(value='', description='executable and args') out = widgets.interactive_output( get_job_script, { 'nodes': inodes, 'ranks_per_node': iranks_per_node, 'affinity': iaffinity, 'command': icommand }) box = widgets.VBox( [widgets.VBox([inodes, iranks_per_node, iaffinity, icommand]), out]) display(box) return
def params(_): if T9.value != '': myboxB.layout.display = 'none' names = [] listsB = [] myboxB.children = listsB for i in range(int(T9.value)): names.append('T' + str(i + 10)) T10 = widgets.Text() T10.disabled = True T10.value = str(i) T10.layout.width = "10%" T11 = widgets.Text() T11.value = '' T11.layout.width = "15%" T12 = widgets.Text() T12.value = '' T12.layout.width = "15%" T13 = widgets.Text() T13.value = '' T13.layout.width = "15%" T14 = widgets.Text() T14.value = '' T14.layout.width = "15%" lists1 = [T10, T11, T12, T13, T14] mybox1 = widgets.HBox(children=lists1) listsB.append(mybox1) myboxB.children = listsB myboxB.layout.display = '' else: myboxB.layout.display = 'none'
def __init__(self, rm, vars=None, show_jobs=True, wide_display=True, enable_datatables=True): self.rm_original = rm if vars is None: self.vars = {} else: self.vars = vars self.show_jobs = show_jobs self.wide_display = wide_display self.enable_datatables = enable_datatables self.layout = widgets.Layout(width='100px') self.layout_label = widgets.Layout(width='200px') self.layout_dropdown = widgets.Layout(width='200px') self.layout_button = widgets.Layout(width='200px') self.t_savedir_base = widgets.Text( value=str(self.vars.get('savedir_base') or rm.savedir_base), layout=widgets.Layout(width='600px'), disabled=False) self.t_filterby_list = widgets.Text( value=str(self.vars.get('filterby_list')), layout=widgets.Layout(width='1200px'), description=' filterby_list:', disabled=False)
def preview(self): #figure, axis = plt.subplots() [height, width] = np.shape(self.images_array[0]) text_y = 0.1 * height text_x = 0.6 * width def display_selected_image(index, text_x, text_y, pre_text, post_text, color): font = { 'family': 'serif', 'color': color, 'weight': 'normal', 'size': 16 } fig = plt.figure(figsize=(15, 10)) gs = gridspec.GridSpec(1, 1) ax = plt.subplot(gs[0, 0]) im = ax.imshow(self.images_array[index], interpolation='nearest') plt.title("image index {}".format(index)) plt.text(text_x, text_y, "{} {:.2f}{}".format(pre_text, self.list_time_offset[index], post_text), fontdict=font) fig.colorbar(im) plt.show() return { 'text_x': text_x, 'text_y': text_y, 'pre_text': pre_text, 'post_text': post_text, 'color': color } self.preview = interact( display_selected_image, index=widgets.IntSlider(min=0, max=len(self.list_files), continuous_update=False), text_x=widgets.IntSlider(min=0, max=width, value=text_x, description='Text x_offset', continuous_update=False), text_y=widgets.IntSlider(min=0, max=height, value=text_y, description='Text y_offset', continuous_upadte=False), pre_text=widgets.Text(value='Time Offset', description='Pre text'), post_text=widgets.Text(value='(s)', description='Post text'), color=widgets.RadioButtons( options=['red', 'blue', 'white', 'black', 'yellow'], value='red', description='Text Color'))
def requestWELocation(self, rows): if self.glove_path is None or self.glove_path.strip() == '': rows += self.addSeparator() rows.append( widgets.HTML( value= '<h4>Set up your Glove model</h4><p>In order to use word embedding, you need ' 'to tell where the glove model locates:</p>')) self.glove_path_input = widgets.Text( value='models/saved/glove/glove.42B.300d.bin', placeholder= 'copy and paste your glove model file location here', description='', disabled=False, layout=widgets.Layout(width='70%')) self.glove_vocab_input = widgets.Text(value=str(self.glove_vocab), placeholder='', description='', disabled=False) self.glove_vector_input = widgets.Text( value=str(self.glove_vector), placeholder='the vector size of the glove model', description='', disabled=False) rows.append(self.glove_path_input) rows.append( widgets.HTML(value='The vocabulary size of the glove model:')) rows.append(self.glove_vocab_input) rows.append( widgets.HTML(value='The vector size of the glove model:')) rows.append(self.glove_vector_input) rows += self.addSeparator() pass
def dashboard_path(self): layout = { 'width': '90%', 'height': '50px', 'border': 'solid', 'fontcolor': 'lightgreen', } layout_two = { 'width': '100%', 'height': '200px', 'border': 'solid', 'fontcolor': 'lightgreen', } style_green = { 'handle_color': 'green', 'readout_color': 'red', 'slider_color': 'blue' } style_blue = { 'handle_color': 'blue', 'readout_color': 'red', 'slider_color': 'blue' } nbgrader_folder_path = widgets.Text(value='./nn-2019-dataset', placeholder='Type something', description='Path:', disabled=False, layout=layout) exam_file_name = widgets.Text( value='NN_Exam_WS18', placeholder='Type something', description='Path:', disabled=False, layout=layout) # value='/path/to/nbgrader/folder/submission', self.nbgrader_folder_path = nbgrader_folder_path.value self.exam_file_name = exam_file_name.value display(nbgrader_folder_path) display(exam_file_name) print('Press button to check if folder is in correct format') button = widgets.Button(description='Check', style=style_blue) display(button) out = widgets.Output() display(out) def on_button_clicked(b): with out: clear_output() print('checking folder: ', nbgrader_folder_path.value) if self.check_folder_structure(nbgrader_folder_path.value, exam_file_name.value): button.button_style = 'success' else: button.button_style = 'danger' button.on_click(on_button_clicked)
def get_input(): text_latt = widgets.Text(description='Lattice constant', value='10.0') text_eps = widgets.Text(description='Dielectric constant', value='10.0') text_q = widgets.Text(description='Charge state', value='1') text_sup = widgets.Text(description='Supercell', value='1') print text_latt display(text_latt) display(text_eps) display(text_q) display(text_sup)
def __init__(self, cluster): self.cluster = cluster applications = self.cluster.get_applications() name_list = [] for application in applications: name_list.append(application.get_information().name.replace( 'fabric:/', '')) self.application_selector = widgets.Dropdown( options=name_list, description='Application:', disabled=False) self.service_selector = widgets.Dropdown(description='Service:', disabled=False) self.dictionary_selector = widgets.Dropdown(description='Dictionary:', disabled=False) self.partition_key_entry = widgets.Text(placeholder='Partition A', description='Optional Key', disabled=False) self.partition_guid_entry = widgets.Text( placeholder='00000000-0000-0000-0000-000000000000', description='Optional ID:', disabled=False) self.query_entry = widgets.Text(placeholder='$top=1', description='Query:', disabled=False) self.query_button = widgets.Button( description='Query', disabled=False, button_style= 'success', # 'success', 'info', 'warning', 'danger' or '' tooltip='Query', icon='check') self.query_button.on_click(self.try_query) self.query_results = widgets.Output( layout={'border': '1px solid black'}) self.application_selector.observe(self.create_application) self.service_selector.observe(self.create_service) self.dictionary_selector.observe(self.create_dictionary) display(self.application_selector) display(self.service_selector) display(self.dictionary_selector) print('Query your dictionary') display(self.partition_key_entry) display(self.partition_guid_entry) display(self.query_entry) display(self.query_button) display(self.query_results) if (len(name_list) > 0): self.create_application(self.application_selector)
def grid(core, loop_pause=0.15): # video # video with button (CV2) def on_live(b): display.clear_output(wait=True) print 'LIVE' core.startContinuousSequenceAcquisition(1000) # time overridden by exposure time.sleep(.2) cv2.namedWindow('Video', cv2.WINDOW_NORMAL) cv2.setWindowProperty('Video', cv2.WND_PROP_ASPECT_RATIO, cv2.WINDOW_KEEPRATIO) cv2.resizeWindow('Video', 500, 500) img = np.zeros((500, 500)) print 'To stop, click window + press ESC' while 1: time.sleep(loop_pause) if core.getRemainingImageCount() > 0: img = core.getLastImage() cv2.imshow('Video', img) k = cv2.waitKey(30) if k == 27: # ESC key; may need 255 mask? break print 'STOPPED' core.stopSequenceAcquisition() def on_close(b): if core.isSequenceRunning(): core.stopSequenceAcquisition() cv2.destroyWindow('Video') def on_corner(b): pos = core.get_xy() b.owner.value = pos print pos live = widgets.Button(description='Live') close = widgets.Button(description='Close') c1 = widgets.Button(description='Corner 1') c2 = widgets.Button(description='Corner 2') file = widgets.Text() save = widgets.Text() live.on_click(on_live) close.on_click(on_close) c1.on_click(on_corner) c2.on_click(on_corner) # calculate: c1.value - c2.value save.on_click(icon='floppy-o') display.display(widgets.HBox([live, close]))
def images_tab(self, output): tfigsize = widgets.Text(value=str( self.vars.get('figsize_images', '(10,5)')), description='figsize:', disabled=False) llegend_list = widgets.Text(value=str( self.vars.get('legend_list', '[model]')), description='legend_list:', disabled=False) t_n_images = widgets.Text(value=str(self.vars.get('n_images', '5')), description='n_images:', disabled=False) t_n_exps = widgets.Text(value=str(self.vars.get('n_exps', '3')), description='n_exps:', disabled=False) brefresh = widgets.Button(description="Display") button = widgets.VBox([ brefresh, widgets.HBox([t_n_exps, t_n_images]), widgets.HBox([ tfigsize, llegend_list, ]), ]) output_plot = widgets.Output() with output: display(button) display(output_plot) def on_clicked(b): self.update_rm() output_plot.clear_output() with output_plot: w, h = tfigsize.value.strip('(').strip(')').split(',') self.vars['figsize_images'] = (int(w), int(h)) self.vars['legend_list'] = get_list_from_str( llegend_list.value) self.vars['n_images'] = int(t_n_images.value) self.vars['n_exps'] = int(t_n_exps.value) self.rm.get_images(legend_list=self.vars['legend_list'], n_images=self.vars['n_images'], n_exps=self.vars['n_exps'], figsize=self.vars['figsize_images']) show_inline_matplotlib_plots() brefresh.on_click(on_clicked)
def create_new_row(self, i, value): """ Creation of a new a Trial row. """ row = [ widgets.Text(value=value, placeholder='', description='', disabled=False, layout=widgets.Layout(width='auto')), widgets.Text(layout=widgets.Layout(width='auto')) ] return row
def define_conversion_formula(self): self.box = widgets.HBox([ widgets.Label("A(x,y) = "), widgets.Text("0.052", layout=widgets.Layout(width='10%')), widgets.Dropdown(options=["+", "-"], layout=widgets.Layout(width='5%'), value="+"), widgets.Text("2.55e-5", layout=widgets.Layout(width='10%')), widgets.Label(" * H(x,Y)") ]) display(self.box)
def draw_interactive(genea_obj, **kwargs): """ This method facilitates drawing interactive genealogical objects by providing an interface for `focused view`, where we may zoom in on a subset of the nodes only. :param genea_obj: :return: """ ns_text = widgets.Text(value='', placeholder='List of nodes (comma separated)', description='Node subset:', disabled=False) rad_text = widgets.Text(value='1', placeholder='1', description='Radius', disabled=False) btn = widgets.Button(description="Plot") output = widgets.Output() def callback(wdgt): ns = [] for n in ns_text.value.split(","): try: n = int(n.strip()) except ValueError: continue if n in genea_obj.nodes: ns.append(n) if len(ns) < 1: ns = None radius = int(rad_text.value.strip()) if radius < 1: radius = 1 with output: output.clear_output() genea_obj.draw(node_subset=ns, radius=radius, **kwargs) plt.show() btn.on_click(callback) display(ns_text, rad_text, btn, output) btn.click()
def display_GUI(self): self.url_caption = widgets.HTML( '<div style="font-size: 1.5em; margin-top:2em; margin-bottom:1em">Insert the URL bellow and press ENTER</div>' ) self.url = widgets.Text(description='URL') self.url.width = '400px' display(self.url_caption, self.url) self.alt_txt_cap = widgets.HTML( '<div style="font-size: 1.5em; margin-top:1em; margin-bottom:1em">Alternatively, paste the text</div>' ) self.alt_txt = widgets.Text(description='Text') self.alt_txt.width = '600px' display(self.alt_txt_cap, self.alt_txt) self.url.on_submit(self.extract_text) self.alt_txt.on_submit(self.extract_text)
def instantiate_objects(self): self.out_graph = widgets.Output() self.out_url = widgets.Output() self.out_func = widgets.Output() self.btn_gen = widgets.Button(description="Generate Vis") self.btn_add = widgets.Button(description="Add Mapping") self.btn_rem = widgets.Button(description="Remove Mapping") self.btn_clear_assigned = widgets.Button(description="Clear") self.sel_cols = widgets.Select(options=[], disabled=False) self.sel_fields = widgets.Select(options=[], disabled=False) self.sel_assigned = widgets.Select(options=[], disabled=False) self.lbl_cols = widgets.Label(value="Columns") self.chk_incidx = widgets.Checkbox(value=False, description='Inc. Index', disabled=False, indent=False) self.lbl_fields = widgets.Label(value="Fields") self.lbl_assigned = widgets.Label(value="Assigned") self.lbl_core = widgets.Label(value="Visualization Core") self.lbl_title = widgets.Label(value="Chart Title:") self.txt_title = widgets.Text(value="My Chart") self.txt_xaxis = widgets.Text(value="") self.txt_yaxis = widgets.Text(value="") self.lbl_xaxis = widgets.Label(value="X Axis") self.lbl_yaxis = widgets.Label(value="Y Axis") self.lbl_charth = widgets.Label(value="Chart Height:") self.lbl_chartw = widgets.Label(value="Chart Width:") self.txt_charth = widgets.Text(value="750") self.txt_chartw = widgets.Text(value="2000") self.lbl_break = widgets.Label( value= "---------------------------------------------------------------------------------" ) self.sel_df = widgets.Select(options=[], description='Data Frame:', disabled=False) self.drp_charts = widgets.Dropdown(options=[], description='Chart Type:', disabled=False)
def get_widgets_per_param(param, value): if isinstance(value, float): return (param, widgets.FloatText( value=value, step=0.05, description=param.split('__')[1], continuous_update=False, disabled=False )) elif isinstance(value, int): return (param, widgets.IntText( value=value, step=1, description=param.split('__')[1], continuous_update=False, disabled=False )) elif isinstance(value, str): return (param, widgets.Text( value=value, description=param.split('__')[1], continuous_update=False, disabled=False )) else: return None
def createSubsetsPanel(self): self.subsetsui = widgets.HBox([], layout=widgets.Layout(display='flex', flex_flow='wrap')) self.updateSubsets() cr = widgets.Button( description='Create subset from selection', disabled=False, button_style='', tooltip='create a new subset from current selection', layout=widgets.Layout(width='100%')) tx = widgets.Text(value='', placeholder='New subset name', disabled=False, layout=widgets.Layout(width='auto')) cr.on_click( lambda e: GlueManagerWidget.createSubsetFromSelection(self, tx)) hb1 = widgets.HBox([cr], layout=widgets.Layout(width='auto')) vb1 = widgets.VBox([self.subsetsui, tx, hb1], layout=widgets.Layout(width='auto')) return vb1
def demos_file(): global filename_widget filename_widget = widgets.Text() display(filename_widget) def handle_submit(sender): print(filename_widget.value) filename_widget.on_submit(handle_submit)
def create_rubrics_feedback(self, answer_sample_object, grade_button): def on_feedback_change(name, change): answer_sample_object.update(name, change) grade_button.description = 'grade : ' \ + str(answer_sample_object.grade) def on_feedback_text_change(name, change): answer_sample_object.feedback_update(name, change) items_layout = Layout(width='auto') box_layout = Layout(display='flex', flex_flow='column', align_items='stretch') row_layout = Layout(display='flex', flex_flow='row', align_items='stretch') combined_list = [] for point in range(answer_sample_object.points): c = \ widgets.Checkbox(name=answer_sample_object.feedback_checkbox[point], value=False, description='-1', disabled=False, layout=items_layout) c.observe(lambda x, point=point: on_feedback_change(point, x), names='value') d = widgets.Text(name=point, value=answer_sample_object.feedback[point], placeholder='Type something', layout=items_layout) d.observe(lambda x, point=point: \ on_feedback_text_change(point, x), names='value') combined_list.append(Box([c, d], layout=row_layout)) return Box(combined_list, layout=box_layout)
def demos_text(): global text_widget text_widget = widgets.Text() display(text_widget) def handle_submit(sender): print(text_widget.value) text_widget.on_submit(handle_submit)
def updateBox(self): """ retrieve optional paramters and display them in the output cell""" for k in vars(self.ml_classifier_cls): if (not k.startswith('__')) and k != 'status' and k != 'model': value = getattr(self.ml_classifier_cls, k) self.parameters[k] = value rows = [ widgets.HTML( value='<h3>Configure your backend machine learning model</h3>' '<p>If you are not sure what the parameters are, just leave them as they are.</p>' '<p>There are <b>' + str(self.leftover) + '</b> samples left unreviewed. The ML model will retrain at a pace ' 'of once per <b>' + str(self.learning_pace) + '</b> samples.') ] for name, value in self.parameters.items(): if type(value) == int: self.parameter_inputs[name] = widgets.BoundedIntText( description=name, value=value, min=-1) rows.append(self.parameter_inputs[name]) elif type(value) == float: self.parameter_inputs[name] = widgets.BoundedFloatText( description=name, value=value) rows.append(self.parameter_inputs[name]) elif type(value) == str: self.parameter_inputs[name] = widgets.Text(description=name, value=value) rows.append(self.parameter_inputs[name]) rows += self.addSeparator(top='10px') + self.addSeparator( top='10px') + [ self.addPreviousNext(self.show_previous, self.show_next) ] self.box = widgets.VBox(rows) pass
def __init__(self, disambiguation_map, start = 0): self.map = disambiguation_map.copy() #Note, deep copy to make sure this is separate self.todo = sorted([v for k,v in self.map.items()], key = lambda x: x[0]) self.position = start self.toDisambiguate = widgets.Label(value = self.todo[self.position][0]) self.disambiguated = widgets.Text(value=self.todo[self.position][0], placeholder='Type something', description='Root:', disabled=False) self.next = widgets.Button(description = 'Next') self.next.on_click(self.next_clicked) self.none = widgets.Button(description = 'None') self.none.on_click(self.none_clicked) self.previous = widgets.Button(description = 'Previous') self.previous.on_click(self.previous_clicked) bottom_rule = widgets.HBox([self.disambiguated,self.next,self.none,self.previous]) bottom_rule.layout.justify_content = 'space-between' self.tool = widgets.VBox([self.toDisambiguate,bottom_rule]) self.tool.layout.justify_content = 'space-around'
def get_name_field(self): """Builds a text field widget for players to enter their name.""" self.name_field = widgets.Text(placeholder="Enter Your Name") self.start_button = widgets.Button(description="Start Game", disabled=True) self.name_field.observe(self.enable_start_game_, names=['value']) self.name_box = widgets.HBox([self.name_field, self.start_button])
def __init__(self, text, solution, *other_correct_choices, is_correct_fun=None, inst=None): self.correct_choices = list(other_correct_choices) self.correct_choices.append(solution) self.is_correct_fun = is_correct_fun textbox = widgets.HTML(value='<h4 style="font-size:14px;">{}</h4>'.format(text)) instbox = widgets.HTML(value='<i>{}</i>'.format(inst)) answer_input = widgets.Text() submit_button = widgets.Button(description="OK") give_up_button = widgets.Button(description="Lösung zeigen") button_box = widgets.HBox(children=[submit_button, give_up_button]) super().__init__(children=[textbox,instbox, answer_input, button_box]) self.answered = False def on_ok_button_clicked(b): if self.answered: return given_answer = answer_input.value answer_input.layout.border = '2px solid lightgreen' if self.is_correct(given_answer) else '2px solid red' submit_button.on_click(on_ok_button_clicked) def on_show_solution_button_clicked(b): answer_input.value = solution answer_input.layout.border = '2px solid lightgreen' answer_input.disabled = True give_up_button.on_click(on_show_solution_button_clicked)