我在启动基于GUI Tkinter的应用程序时试图隐藏终端,但是当我双击OSX上的app.py文件时,会出现终端窗口.我已经尝试将扩展名更改为.pyw并尝试使用/ usr/bin/pythonw启动它,但无论如何,终端窗口仍会出现.
我甚至尝试添加下面的try/except,但是当我运行它时,我收到错误:出现在终端窗口中的'无效命令名称"console"'.
from Tkinter import *
class MainWindow(Tk):
def __init__(self):
Tk.__init__(self)
try:
self.tk.call('console', 'hide')
except TclError, err:
print err
win = MainWindow()
win.mainloop()
Run Code Online (Sandbox Code Playgroud)
我无法找到任何方法来隐藏终端窗口出现.有人有任何想法吗?
我有一个控制自动测试仪的Tcl脚本.到目前为止,它是一个控制台程序,它在命令提示符下输入用户输入.一位同事写了一个可以由脚本启动的Tk GUI.我自己从未使用过Tk,所以我不理解很多语法.
在测试开始时,脚本必须从操作员处获取单元序列号.这是我的同事写的那个功能:
proc GetSerialNumber {} {
global gUserInterfaceBarCode
DisplayMessage "Enter serial number:"
.c.serialnumberbox configure -state normal
focus .c.serialnumberbox
bind .c.serialnumberbox <Return> { set gUserInterfaceBarCode [.c.serialnumberbox get] }
tkwait variable gUserInterfaceBarCode
#grid forget .c.serialnumberbox
.c.serialnumberbox configure -state disabled
}
Run Code Online (Sandbox Code Playgroud)
DisplayMessage 是一个简单地更新GUI上的文本标签的过程.
我不喜欢有一个gUserInterfaceBarCode用于保存序列号的全局变量这一事实.有没有办法使用局部变量而让程序返回该值?
如果我理解正确,如果该行tkwait variable gUserInterfaceBarCode被取出,该函数将不会阻塞,直到该变量发生变化.这是从GUI元素捕获用户输入的最佳方法吗?
我正在尝试在 Ubuntu 10.04 中编译 VRip,使用网站http://graphics.stanford.edu/software/vrip/guide/作为指南。它依赖于 Tcl 和 Tk 的安装——我从突触包管理器那里获得了这些的最新版本。
当我写“make Depend”时,出现错误:
在从 vripInit.cc:30 包含的文件中:vripInit.h:22:17:错误:tcl.h:没有这样的文件或目录 vripMain.cc:22:16:错误:tk.h:在文件中没有这样的文件或目录包含自 vripMain.cc:28: vripInit.h:22:17: 错误: tcl.h: 没有这样的文件或目录 在包含自 vripMiscCmds.cc:29 的文件中: vripMiscCmds.h:22:17: 错误: tcl.h : 没有这样的文件或目录 在从 vripFillCmds.cc:29 包含的文件中: vripFillCmds.h:22:17: 错误: tcl.h: 在从 vripFileCmds.cc:29 包含的文件中: vripFileCmds.h:22 :17: 错误: tcl.h: 没有这样的文件或目录在 vripGridCmds.cc 包含的文件中:29: vripGridCmds.h:22:17: 错误: tcl.h: 没有这样的文件或目录在 vripRangeCmds.cc 包含的文件中:36: vripRangeCmds.h:21:17: 错误: tcl.h: 没有这样的文件或目录在 vripGUICmds.cc:37 包含的文件中: vripGUICmds.h:22:17:错误:tcl.h:没有这样的文件或目录 vripGUICmds.cc:43:16:错误:tk.h:没有这样的文件或目录在从 vripPlyCmds.cc:32 包含的文件中:vripPlyCmds.h:22:17:错误: tcl.h: 没有那个文件或目录 rm makedep.bak
它似乎在寻找头文件而不是找到它们。但我不知道在哪里告诉它看。有更多经验的人可以帮忙吗?我花了好几个小时试图解决这个问题,但没有成功......:S
谢谢,平板
我一直在关注此处对输入框的验证。下面的代码来自带有附加条件的答案,即如果输入的值是,'Q'则程序将添加'test'到 Entry 值的开头。
但是,一旦插入此值,所有验证似乎都将超出窗口,并且条目允许大写值。对我的程序进行的一些测试显示验证命令(OnValidate在本例中)不会在 Entry 的任何其他事件(键、焦点输入/输出等)上被调用。
import Tkinter as tk
class MyApp():
def __init__(self):
self.root = tk.Tk()
vcmd = (self.root.register(self.OnValidate),
'%d', '%i', '%P', '%s', '%S', '%v', '%V', '%W')
self.entry = tk.Entry(self.root, validate="key",
validatecommand=vcmd)
self.entry.pack()
self.root.mainloop()
def OnValidate(self, d, i, P, s, S, v, V, W):
if S == "Q":
self.entry.insert(0,"test")
# only allow if the string is lowercase
return (S.lower() == S)
app=MyApp()
Run Code Online (Sandbox Code Playgroud)
我这样做的原因是我希望 Entry 显示一个默认值,如果它的值在用户进行任何更改后保留为空。(即我的情况是if not P在焦点上)
任何想法如何实现这一点或上面出了什么问题,非常感谢。
我这样做的原因是因为我试图将窗口设置在屏幕的中心.我正在使用网格不打包,我已阅读有关使用wm grid但不了解如何设置它.我也不明白为什么. cget -width要回来0我认为格栅应该在没有给出选项时设置大小?
set width [. cget -width]
set height [. cget -height]
puts $height
puts $width
set x [expr { ( [winfo vrootwidth .] - $width ) / 2 }]
set y [expr { ( [winfo vrootheight .] - $height ) / 2 }]
wm title . "a3q2"
wm geometry . ${width}x${height}+${x}+${y}
Run Code Online (Sandbox Code Playgroud)
这次我做错了什么?PS作业我不只是想要一个代码发布.谢谢
我在框架内有一个画布,我说过画布应该是 250x250。但出于某种原因,它被创建得更大,在右侧和底部有额外的空间。这是我的代码......有什么想法吗?
from tkinter import *
from tkinter import ttk
from player import player0
alpha = ('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z')
class GUI(Frame):
def __init__(self, master):
Frame.__init__(self, master)
self.boardsize = 250
self.sqsize = self.boardsize//5
master.title("Canvas with extra space")
self.initialdraw()
self.grid(row=0,column=0)
def initialdraw(self):
mainframe = ttk.Frame(self, padding=(5,5,5,5))
mainframe.grid(column=0, row=0, sticky=(N, S, E, W))
self.board = Canvas(mainframe, width=self.boardsize, height=self.boardsize,bg='white')
self.board.grid(row=1,column=0)
for row in range(5):
for col in range(5):
top = row * self.sqsize
left = col * self.sqsize
bottom = row * self.sqsize + self.sqsize -2 …Run Code Online (Sandbox Code Playgroud) 我正在尝试在Mac上安装WordNet(OS 10.9.2).我尝试了以下内容
但是在make我遇到一些错误的时候.然后我安装了XQuartz-2.7.5.我还是遇到了一些错误make.接下来,我已经安装了Xcode,但仍然没有解决问题.这个问题建议安装Tcl/TK,我尝试了但是我仍然遇到了以下错误make
/Applications/Xcode.app/Contents/Developer/usr/bin/make all-recursive
Making all in doc
Making all in html
make[3]: Nothing to be done for `all'.
Making all in man
make[3]: Nothing to be done for `all'.
Making all in pdf
make[3]: Nothing to be done for `all'.
Making all in ps
make[3]: Nothing to be done for `all'.
make[3]: Nothing to be done for `all-am'.
Making all in dict
make[2]: Nothing to be done for `all'. …Run Code Online (Sandbox Code Playgroud) 在ubuntu上从CLI启动gitk我遇到了这个错误
vihaan@Trojan :~$ gitk
application-specific initialization failed: unknown color name "S_base3"
Error in startup script: unknown color name "S_base3"
(database entry for "-background" in widget ".")
invoked from within
"load /usr/lib/x86_64-linux-gnu/libtk8.6.so Tk"
("package ifneeded Tk 8.6.1" script)
invoked from within
"package require Tk"
(file "/usr/bin/gitk" line 10)
Run Code Online (Sandbox Code Playgroud)
怎么解决?
我需要检查字符串(输入框上的用户输入)是否为空,并在按下"播放"按钮后根据该条件执行某些操作.这是我的脚本:
entry .eInput -width 50 -relief sunken -justify center -textvariable Input
button .bAction -text "Play" -width 30 -height 5 -activebackground green -font "-12"
bind .bAction <1> {
if {$Input ne ""}
{ puts "string is not empty"}
else { puts "string is empty"}
}
Run Code Online (Sandbox Code Playgroud)
但是当我按下"播放"按钮时,这就是错误:
wrong # args: no script following "$Input ne """ argument
wrong # args: no script following "$Input ne """ argument
while executing
"if {$Input ne ""}"
(command bound to event)
Run Code Online (Sandbox Code Playgroud)
有关如何解决它的任何想法?
我有用python3和tkinter模块编写的简单应用程序.我想编写自定义小部件,需要发送自定义事件.
为什么下面的示例代码不起作用?
#!/usr/bin/env python3
from tkinter import *
class MyWidget(Listbox):
def __init__(self, master, *args, **kwargs):
super().__init__(master, *args, **kwargs)
# ===================
# error: _tkinter.TclError: only one event specification allowed
self.bind('<<ListboxSelect>>', lambda e: self.event_generate('MyEvent'))
# ===================
class App(Tk):
def __init__(self):
super().__init__()
w = MyWidget(self)
w.bind('MyEvent', lambda e: print('It\'s working'))
w.pack()
w.insert(END, 'ddddddd')
if __name__ == '__main__':
app = App()
app.mainloop()
Run Code Online (Sandbox Code Playgroud) tk-toolkit ×10
tcl ×5
python ×4
tkinter ×4
macos ×2
build ×1
canvas ×1
git ×1
gitk ×1
grid ×1
if-statement ×1
python-3.x ×1
ubuntu ×1
validation ×1
wordnet ×1
x11 ×1