我有一个用户界面按钮。我想在用户按下按钮时显示文本,并在用户释放按钮时隐藏文本。
我怎样才能做到这一点?
我正在使用按钮调用函数,但函数的输出似乎没有保存。
我正在创建一个交互式 jupyter 笔记本,其设计为在单击按钮时执行功能。例如,第一个按钮称为“ Get data”,它将创建新变量。然后第二个按钮“ Analyze data”将对变量进行一些分析。问题是“ Get data”的输出没有保存在函数之外。
# GET DATA
get_data_button = widgets.Button(description='Get Data')
def get_data(b):
data = 10
print(data)
return data
# DISPLAY BUTTON
get_data_button.on_click(get_data)
display(get_data_button)
Run Code Online (Sandbox Code Playgroud)
我期待在我可以做的功能之后
print(data)
Run Code Online (Sandbox Code Playgroud)
并返回 10
相反,它说:
名称“数据”未定义
当按下循环中的一个按钮时,其背景颜色变为红色,当按下另一个按钮时,其颜色也变为红色。但剩下的按钮仍然是红色的,不会再次变成蓝色。如何只将按下的按钮更改为红色,而将其他按钮更改为蓝色?
struct Box: Identifiable {
var id: Int
var title: String
}
struct MainView: View {
let boxes:[Box] = [
Box(id: 0, title: "Home"),
Box(id: 1, title: "Subjects"),
Box(id: 2, title: "attendence"),
Box(id: 3, title: "H.W"),
Box(id: 4, title: "Quizes"),
Box(id: 5, title: "class schedule"),
Box(id: 6, title: "Exam Schedule"),
Box(id: 7, title: "Inbox"),
Box(id: 8, title: "Evalouation"),
]
@Binding var showMenu: Bool
var body: some View{
VStack {
ScrollView(.horizontal,showsIndicators: false){
HStack{
ForEach(boxes, id: \.id) {
box in
BoxView(box: box) …Run Code Online (Sandbox Code Playgroud) 我正在使用刀片模板,所有文件内容都在视图中,我的项目需要两种语言,如何以最简单的方式制作按钮切换器语言?有人能帮我吗?
谢谢
我有一个 Gtk.Button,我想减少按钮内部的左右填充,因此按钮的标签在左侧和右侧显示为较小的边距。
我可以使用...来增加利润
label = button.get_child()
label.set_margin_start(50)
label.set_margin_end(50)
Run Code Online (Sandbox Code Playgroud)
但我无法减少利润。将边距设置为零没有效果...
label = button.get_child()
label.set_margin_start(0)
label.set_margin_end(0)
Run Code Online (Sandbox Code Playgroud)
我还尝试获取样式上下文,并读取边距属性......
label = button.get_child()
style_context = label.get_style_context()
margin = style_context.get_margin(Gtk.StateFlags.NORMAL)
print('left = %s' % margin.left)
print('right = %s' % margin.right)
print('top = %s' % margin.top)
print('bottom = %s' % margin.bottom)
Run Code Online (Sandbox Code Playgroud)
但对于各方来说都已经为零了……
left = 0
right = 0
top = 0
bottom = 0
Run Code Online (Sandbox Code Playgroud)
如何减少按钮内文本的左右填充?
编辑:我在下面添加了测试代码。
basic_window.py
#!/usr/bin/python3
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import GLib
from gi.repository import Gtk
class MainWindowHandlers(Gtk.Window):
def …Run Code Online (Sandbox Code Playgroud) 我目前正在尝试使用数据绑定来设置“切换”按钮的检查状态,但由于某种原因我的状态永远不会改变?
在我的设置页面中,我执行以下操作:
文件- SettingsFragment - SettingsViewModel - SettingsLayout.XML
设置视图模型
private val _checked = MutableLiveData<Boolean>()
val checked : LiveData<Boolean> = _checked
Run Code Online (Sandbox Code Playgroud)
设置布局.XML
<Switch
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|center"
android:layout_marginRight="@dimen/margin_big
android:checked="@{viewModel.checked}"/>
Run Code Online (Sandbox Code Playgroud)
我已经仔细检查以确保在我的SettingsFragment中我也执行了DataBindingUtil.inflate并传递了我的 SettingsViewModel。
我正在使用 bootstrap 来设置下拉按钮的样式,并且我希望将按钮文本更改为从下拉列表中选择的任何项目。我猜 JavaScript 是实现这一点的最佳方法,但我还不太熟悉它。任何帮助将不胜感激。
这是我的第一个下拉按钮的 html。谢谢
<button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Genre
</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenu1">
<button class="dropdown-item" type="button">Adventure</button>
<button class="dropdown-item" type="button">Sci-Fi</button>
<button class="dropdown-item" type="button">Comedy</button>
</div>
Run Code Online (Sandbox Code Playgroud) 在搜索并尝试了一切之后,我无法摆脱表单上的 iOS 样式。
HTML 代码:
<form method="post" >
<fieldset style= "border-width: 0px;" >
<input style="font-size : 30px; height:48px; width:50px;" type="text" name="pone" id="pone" autocomplete="off">
<input style="font-size : 30px; height:48px; width:50px;" type="text" name="ptwo" id="ptwo" autocomplete="off">
<input style="font-size : 30px; height:48px; width:50px;" type="text" name="pthree" id="pthree" autocomplete="off">
<input style="font-size : 30px; height:48px; width:50px;" type="text" name="pfour" id="pfour" autocomplete="off">
<input style="font-size : 30px; height:48px; width:50px;" type="text" name="pfive" id="pfive" autocomplete="off">
<label>
<INPUT style="width:250px; height:50px; font-size : …Run Code Online (Sandbox Code Playgroud) 我在为 OutlinedButton 添加 pad 时遇到问题,我一直在使用 OutlinedButton,并且我决定使用 OutlinedButton,因为该按钮已折旧。但是,在未定义 padding 参数的情况下,按钮的用法有所不同。我尝试将 OutlinedButton 包装在 ButtonTheme 中,但没有任何效果,现在我正在使用 Padding,如下面的代码示例所示。
new Column(children: [
new Row(children: [
//5th row
new Expanded(
child: Padding(
child: new OutlinedButton(
child: new Text(
"Main Page",
style: TextStyle(
fontFamily: 'NotoSans',
fontSize: 20.0,
fontWeight: FontWeight.w400),
),
onPressed: () {
Navigator.of(context).push(_gotoMainPage());
},
padding: EdgeInsets.all(20),
)),
)
]),
])
],
),
Run Code Online (Sandbox Code Playgroud)
提前致谢。