我试图删除 a 上的默认背景Button,但是Button当用户用鼠标悬停在按钮上时,将其突出显示为橙色。到目前为止,这是我想出的;
<Window.Resources>
<Style TargetType="{x:Type Button}">
<Setter Property="FontSize" Value="20" />
<Setter Property="Margin" Value="5" />
<Setter Property="MaxHeight" Value="30" />
<Setter Property="Width" Value="150" />
<Setter Property="Background" Value="Transparent" />
<Setter Property="BorderBrush" Value="Transparent" />
<Setter Property="Cursor" Value="Hand" />
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="Orange"/>
</Trigger>
</Style.Triggers>
</Style>
</Window.Resources>
Run Code Online (Sandbox Code Playgroud)
但是,当用户将鼠标悬停在按钮上时,它仍然以默认的蓝色突出显示,而不是我想要的橙色。如何修改它,以便按钮的文本逐渐以橙色突出显示?
按下按钮调用函数时,我无法将参数传递给函数。可以用 kivy 语言这样做:
Button:
on_press: root.my_function('btn1')
Run Code Online (Sandbox Code Playgroud)
但我想用 python 来做,因为我想用循环创建更多数量的按钮。目前我在 python 中调用我的函数是这样的:
Button(on_press=self.my_function)
Run Code Online (Sandbox Code Playgroud)
但正如我所说,如果我尝试将参数传递给这样的函数,我会收到“AssertionError: None is not callable”,如下所示:
Button(on_press=self.my_function('btn1'))
Run Code Online (Sandbox Code Playgroud) 我这里有一个程序,里面有两个按钮。我正在尝试将它们的位置更改为它们之间的空间,因为目前它们直接位于彼此下方。我应该怎么做才能改变按钮的位置?
def menu():
import tkinter
window=tkinter.Tk()
window.title('Lightning Parties')
window.configure(background='turquoise')
lbl=tkinter.Label(window, text='Welcome to Lightning Parties!', fg='purple', bg='turquoise', font=('comicsans', 14))
lbl.pack()
#here are the buttons
lbl=tkinter.Button(window, text='Returning customer options', fg='white', bg='purple', font=('comicsans', 12),command=combine_funcs(window.destroy, customer_login))
lbl.pack()
lbl=tkinter.Button(window, text='Register as a customer', fg='white', bg='purple', font=('comicsans', 12),command=combine_funcs(window.destroy, customer_details))
lbl.pack()
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激!
我正在创建一个 android 应用程序,我想在其中创建 ID 最大值大小的布尔数组,以便我可以唯一地存储按钮上的更改。
假设我的按钮 id 是 102931,当用户单击按钮时,我将更改布尔数组的第 102931 个元素,以便稍后我可以检查其中更改的值。
现在我的问题是
任何视图的 ID(最小-最大)范围是多少?
我正在尝试创建不同的框架并切换/销毁它们,以便您可以像在普通 iOS 应用程序中一样在窗口之间移动。
为此,我需要将小部件(组件)放置在框架(容器)中。
但是,当我尝试向框架添加按钮时,它不会将其打包到右侧。
这是我的代码: from tkinter import *
root=Tk()
root.geometry('500x500')
root.title('Good morning :)')
frame1=Frame(root,width=500,height=500,bg='green')
frame1.pack()
button1=Button(frame1,text='Hello')
button1.pack(side='bottom')
Run Code Online (Sandbox Code Playgroud) 例子:
<ListBox Name="List"
ItemsSource="{Binding Items}"
SelectedIndex="{Binding SelectedIndex}">
<ListBox.ItemTemplate>
<DataTemplate>
<DockPanel >
<Button DockPanel.Dock="Left" Content="Show" Command="{Binding ShowCommand}" CommandParameter="{Binding}"/>
<TextBlock Text="{Binding }"/>
</DockPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Run Code Online (Sandbox Code Playgroud)
单击按钮什么也不做。我试图将命令绑定到 外面的按钮DataTemplate并且它起作用了。我还尝试将按钮注册DataTemplate到 a 中Click_event,这确实有效。
为什么该命令在 DataTemplate 中不起作用?
我正在尝试添加一个指向联系页面的自定义链接按钮 - 首先,如果条件显示“联系我们”文本和按钮上的自定义 URL,而不是“添加到购物篮”按钮。
怎么做?到目前为止,这是我的代码。它显示属于“64”类别的每个产品的自定义按钮文本。这正是我想要的。但是如何添加该按钮将功能从购物车按钮更改为自定义链接按钮?我想如果必须更改此购物车按钮功能。如何?
add_filter( 'woocommerce_product_single_add_to_cart_text', 'woo_custom_cart_button_text' );
function woo_custom_cart_button_text() {
global $product;
$cat_id = 64;
$product->get_category_ids();
if ( in_array( $cat_id, $product->get_category_ids() ) ) {
return __( 'Contact us', 'woocommerce' );
}
else {
return __( 'Add to Basket', 'woocommerce' );
}
}
Run Code Online (Sandbox Code Playgroud) 我正在创建按钮并以编程方式将它们添加到 LinearLayout。但是,我正在努力更改按钮大小。在下面的代码中,无论我在 deleteBtn.setWidth(num) 和 deleteBtn.setHeight(num) 中输入什么数字,都没有任何变化。
private void populateHorizontalLayouts(CustomMessageEvent event) {
// Need to remove all views each time an user adds a number
// so that the same number is not rendered multiple times.
nameAndNumbersLayout.removeAllViews();
//displayedNamesAndNumbers.add(event.getCustomMessage());
for(int i =0; i < displayedNamesAndNumbers.size(); i++){
String displayedNumberAndName = displayedNamesAndNumbers.get(i);
LinearLayout horizontalLayout = new LinearLayout(view.getContext());
horizontalLayout.setOrientation(LinearLayout.HORIZONTAL);
horizontalLayout.setId(i);
Button deleteBtn = new Button(view.getContext());
deleteBtn.setId(i);
deleteBtn.setText("Delete");
deleteBtn.setWidth(5);
deleteBtn.setHeight(5);
TextView nameAndNumView = new TextView(view.getContext());
nameAndNumView.setId(i);
nameAndNumView.setText(displayedNumberAndName);
horizontalLayout.addView(deleteBtn);
horizontalLayout.addView(nameAndNumView);
nameAndNumbersLayout.addView(horizontalLayout);
}
}
Run Code Online (Sandbox Code Playgroud)
我应该写什么才能改变按钮大小?
我正在制作一个网站,当我单击一个按钮时,我希望在特定地址打开一个新选项卡。
这是我的按钮的 html:
<button id="AsDownload" onclick="AsDownload();">Download</button>
Run Code Online (Sandbox Code Playgroud)
这是我的javascript:
function AsDownload(){
chrome.tabs.create({url:"https://alexanderhawking.itch.io/asteroid-racer"});
};
Run Code Online (Sandbox Code Playgroud)
但它不起作用,我不知道为什么,有人可以帮助我吗?