当我运行此代码时,文件选择器出现,然后当我完成它时,我无法输入条目小部件,直到我专注于另一个窗口然后回来.为什么会这样?
import tkinter as tk
from tkinter.filedialog import askopenfilename
location = ''
start = tk.Tk()
tk.Label(text='What is the name of your table?').pack()
box = tk.Entry(start, exportselection=0, state=tk.DISABLED)
box.pack()
button = tk.Button(start, text='OK', command=lambda e: None)
button.pack()
location = askopenfilename(defaultextension='.db',
title="Choose your database",
filetypes=[('Database Files', '.db'), ('All files', '*')])
box.config(state=tk.NORMAL)
start.mainloop()
Run Code Online (Sandbox Code Playgroud) 我找到了以下关于如何设置的文档customView
.但是当我将id
我的布局更改为"text1"和"icon"时,setText()
并且setIcon()
不起作用.
public TabLayout.Tab setCustomView(int layoutResId)
设置要用于此选项卡的自定义视图.
如果膨胀的布局包含一个
TextView
ID为,text1
那么将使用给定的值更新setText(CharSequence)
.同样,如果此布局包含ImageView
带有ID的图标,则它将使用给定的值进行更新setIcon(Drawable)
.
(来源:http://developer.android.com/reference/android/support/design/widget/TabLayout.Tab.html#setCustomView(int))
谁能举个例子说明这是如何运作的?
Java代码:
TabLayout.Tab tabAdd = tabLayout.getTabAt(0);
tabAdd.setCustomView(R.layout.tab_layout_custom_view);
tabAdd.setText("Add");
tabAdd.setIcon(R.mipmap.add_tab).setText("Add");
Run Code Online (Sandbox Code Playgroud)
布局代码:
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="@+id/icon"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:id="@+id/text1"
android:gravity="center"
android:layout_below="@+id/icon" />
Run Code Online (Sandbox Code Playgroud)