我正在使用Tkinter在Python2.7中使用GUI,我有一个恼人的问题.
我想定义所有小部件使用的默认字体,如果可能的话,在一行中.此行仅修改Entry或ComboBox中使用的字体:
root.option_add("*Font", "courier 10")
Run Code Online (Sandbox Code Playgroud)
但不是示例复选框的标签.
我发现预定义的字体存在"TkDefaultFont",但我无法更改其配置:
print tkFont.Font(font='TkDefaultFont').configure()
tkFont.Font(font='TkDefaultFont').config(family='Helvetica', size=20)
tk.TkDefaultFont = tkFont.Font(family="Helvetica",size=36,weight="bold")
print tkFont.Font(font='TkDefaultFont').configure()
Run Code Online (Sandbox Code Playgroud)
回报:
{'family':'DejaVu Sans','weight':'normal','slant':'roman','overstrike':0,'underline':0,'size': - 12} {'family': 'DejaVu Sans','weight':'normal','slant':'roman','overstrike':0,'underline':0,'size': - 12}
(没有错误,但没有任何改变!)
我做错了什么?
我的问题几乎与此相同: 显示子进程stdout的小部件? 但是更进一步。
我有以下代码(python2.7):
def btnGoClick(p1):
params = w.line.get()
if len(params) == 0:
return
# create child window
win = tk.Toplevel()
win.title('Bash')
win.resizable(0, 0)
# create a frame to be able to attach the scrollbar
frame = ttk.Frame(win)
# the Text widget - the size of the widget define the size of the window
t = tk.Text(frame, width=80, bg="black", fg="green")
t.pack(side="left", fill="both")
s = ttk.Scrollbar(frame)
s.pack(side="right", fill="y")
# link the text and scrollbar widgets
s.config(command=t.yview)
t.config(yscrollcommand=s.set)
frame.pack()
process = subprocess.Popen(["<bashscript>", …Run Code Online (Sandbox Code Playgroud) 使用Python 2.7,我想将"Entry"小部件的状态转换为正常/禁用感谢一个checkbutton.
在这个问题的帮助下,使用checkbutton禁用小部件?,我可以用1个checkbutton和1个Entry进行
#!/usr/bin/env python2.7
# -*- coding: utf-8 -*-
import Tkinter as tk
root = tk.Tk()
class Principal(tk.Tk):
def __init__(self, *args, **kwargs):
self.foo = tk.StringVar()
self.nac = tk.IntVar()
self.ck1 = tk.Checkbutton(root, text='test',
variable=self.nac, command=self.naccheck)
self.ck1.pack()
self.ent1 = tk.Entry(root, width=20, background='white',
textvariable=self.foo, state='disabled')
self.ent1.pack()
def naccheck(self):
print "check"
if self.nac.get() == 0:
self.ent1.configure(state='disabled')
else:
self.ent1.configure(state='normal')
app = Principal()
root.mainloop()
Run Code Online (Sandbox Code Playgroud)
当我想要2对或更多对(问题按钮/条目)时出现问题.在我的最终界面中,我可能有20个或更多这一对,所以我想避免使用20个或更多相同的"naccheck"方法.
我试过这个:
#!/usr/bin/env python2.7
# -*- coding: utf-8 -*-
import Tkinter as tk
root = tk.Tk()
class Principal(tk.Tk):
def …Run Code Online (Sandbox Code Playgroud)