我在python(3)中使用tk,虽然我认为这适用于任何语言.我希望得到标题栏之外的tk窗口的当前x,y坐标:
import tkinter
root = tkinter.Tk()
Run Code Online (Sandbox Code Playgroud)
但是,使用root.winfo_y()给我的坐标包括标题栏的深度.对于屏幕左上角的窗口:
root.winfo_x(), root.winfo_y() # returns (0, 22)
Run Code Online (Sandbox Code Playgroud)
换句话说,运行:
root.geometry('+{}+{}'.format(root.winfo_x(), root.winfo_y()))
Run Code Online (Sandbox Code Playgroud)
每当我调用它时,它将向下移动22个像素(标题栏的高度).如何获得整个窗口的实际坐标?
我试图在R中创建一个交互式直方图,其宽度可以通过移动滑块或在文本框中输入值来调整.除此之外,我还想为用户提供一个保存特定箱宽度图的选项.
为此,我发现'aplpack'库的'gslider'功能是一个很好的起点.我试图修改它以满足我的目的,并了解更多有关Tcl/Tk结构的信息.但我现在卡住了,无法继续,主要是因为我还没有完全理解如何在函数之间捕获和传输滑块值.
以下是我还没有真正理解的代码片段.这些来自'gslider'函数的源代码.
# What is the rationale behind using the 'assign' function here and at
# other instances in the code?
img <- tkrplot::tkrplot(gr.frame, newpl, vscale = 1, hscale = 1)
tkpack(img, side = "top")
assign("img", img, envir = slider.env)
# I understand the below lines when considered individually. But collectively,
# I am having a difficult time comprehending them. Most importantly, where
# exactly is the slider movement captured here?
sc <- tkscale(fr, from = sl.min, to = …Run Code Online (Sandbox Code Playgroud) 使用网格几何管理器时.假设你有:
import tkinter as tk
from tkinter import ttk
root = tk.Tk()
root.rowconfigure(0, weight=1)
root.columnconfigure(0, weight=1)
ttk.Button(root, text="Hello World").grid(sticky=tk.NSEW)
root.mainloop()
Run Code Online (Sandbox Code Playgroud)
您指定行/列权重的部分也可以编码为:
root.grid_rowconfigure(0, weight=1)
root.grid_columnconfigure(0, weight=1)
Run Code Online (Sandbox Code Playgroud)
对于此示例,什么是正确的方法:widget.rowconfigure或widget.grid_rowconfigure?为什么?
奖励:从实施POV,为什么两者都有效?
我无法让红宝石成功地要求'tk'.我正在使用rvm,ruby 2.0.0,ActiveTcl-8.6和Ubuntu 12.04 LTS.我已经运行的愿望提供了ActiveTcl,它似乎是工作.
我查看了RVM站点http://rvm.io/integration/tk和几个StackOverflow问题,比如这个带有TK安装的RVM Ruby(OSX).
我试过rvm重新安装2.0.0 --enable-shared --enable-pthread --with-tk --with-tcl在不同版本的ruby上多次没有成功.
有什么想法吗?
当我运行irb并且确实需要'我得到以下内容:
LoadError: cannot load such file -- tk
from /home/brooks/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /home/brooks/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from (irb):2
from /home/brooks/.rvm/rubies/ruby-2.0.0-p353/bin/irb:12:in `<main>'
Run Code Online (Sandbox Code Playgroud)
当这工作时,我认为你应该得到真实的回报.
我还没有尝试过其他任何事情,主要是因为我无法弄清楚还有什么可做的.我一直在研究如何工作并检查加载路径与ruby -e'$:'我得到
[brooks@ubuntu:~/sites/depot]$ruby -e 'puts $:'
/home/brooks/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/site_ruby/2.0.0
/home/brooks/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/site_ruby/2.0.0/x86_64-linux
/home/brooks/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/site_ruby
/home/brooks/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/vendor_ruby/2.0.0
/home/brooks/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/vendor_ruby/2.0.0/x86_64-linux
/home/brooks/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/vendor_ruby
/home/brooks/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0
/home/brooks/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/x86_64-linux
Run Code Online (Sandbox Code Playgroud)
我认为这看起来像你期望的那样.对不起格式化,我是编辑的新手.
继续认为这是一个路径问题,我在我的文件中找到了tk.rb并在irb中尝试了以下内容:
2.0.0-p353 :003 > require '/home/brooks/.rvm/src/ruby-2.0.0-p353/ext/tk/lib/tk'
LoadError: cannot load such file -- tcltklib
from /home/brooks/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Perl Tk创建一个简单的记事本,如GUI.我使用Scrolled小部件创建了一个带有两个滚动条的Text小部件 - 一个在右边,一个在底部.两个滚动条相遇的地方看起来像这样:

但是,我想让它看起来像微软在"记事本"应用程序中看到的.这就是我想要的:

正如你所看到的,现在有一个"空方块",两个滚动条相遇.记事本的另一个功能是这个"方形"可用于调整窗口大小.我希望能够实现同样的目标.
我该怎么做呢?
谢谢!
我有一个简单的Tcl脚本,它创建一个带菜单的窗口.
#! /usr/bin/tclsh
package require Tk
# Create the main message window
message .m -text {Hello Tcl!} -background white
pack .m -expand true -fill both -ipadx 100 -ipady 40
# Create the main menu bar with a Help-About entry
menu .menubar
menu .menubar.help -tearoff 0
.menubar add cascade -label Help -menu .menubar.help -underline 0
.menubar.help add command -label {About Hello ...} \
-accelerator F1 -underline 0 -command showAbout
# Define a procedure - an action for Help-About
proc showAbout {} …Run Code Online (Sandbox Code Playgroud) 我目前正在寻找在Tkinter应用程序中显示PDF文件的可能性(例如在Frame小部件或类似内容中显示它们).
这个问题已经有了解决方案吗?
我已经搜索了SO,使用了ddg和其他人没有为此目的找到任何东西.我唯一发现的是如何将tk.Canvas的内容打印到PDF - 有没有办法将PDF加载到画布中?
我正在运行一个脚本,提示用户输入文件。除了打开的文件浏览器外,没有gui。我有2个选项:浏览文件,或使用选择整个文件夹askdirectory()。后者在所有其他窗口的顶部打开,但是第一个在所有窗口的下面打开,我必须最小化其他窗口才能找到它。
这是我用于这些操作的方法
from Tkinter import Tk
from tkFileDialog import askdirectory, askopenfilename
root = Tk()
root.withdraw()
self.inpath = askdirectory() # To open entire folder
Path = askopenfilename() # Open single file
root.destroy() # This is the very last line in my main script.
Run Code Online (Sandbox Code Playgroud)
这就是我代码中与Tk相关的所有内容。askdirectory打开在顶部,askopenfilename没有。
有没有办法强迫它在顶部打开?
下面是一些创建4个单选按钮的示例代码,2个使用int,2个使用str:
from tkinter import *
class test:
def __init__(self):
wind = Tk()
frame1 = Frame(wind)
frame1.pack()
self.v1 = IntVar()
self.v2 = StringVar()
int1 = Radiobutton(frame1, text = 'int1', variable = self.v1, value = 1, command = self.ipress)
int2 = Radiobutton(frame1, text = 'int2', variable = self.v1, value = 2, command = self.ipress)
str1 = Radiobutton(frame1, text = 'str1', variable = self.v2, value = '1', command = self.spress)
str2 = Radiobutton(frame1, text = 'str2', variable = self.v2, value = '2', command …Run Code Online (Sandbox Code Playgroud) 我主要在Spyder工作,构建需要弹出文件夹或文件浏览窗口的脚本.
下面的代码在spyder中完美运行.在Pycharm,askopenfilename运作良好,而askdirectory什么都不做(卡住).但是,如果在调试模式下运行 - 脚本运行良好.我试图从SAS jsl运行脚本 - 同样的问题.
任何想法我该怎么办?Python 3.6 Pycharm 2017.2
谢谢.
我使用的准则包括:
import clr #pythonnet 2.3.0
import os
import tkinter as tk
from tkinter.filedialog import (askdirectory,askopenfilename)
root = tk.Tk()
root.withdraw()
PPath=askdirectory(title="Please select your installation folder location", initialdir=r"C:\Program Files\\")
t="Please select jdk file"
if os.path.exists(os.path.expanduser('~\Documents')):
FFile = askopenfilename(filetypes=(("jdk file", "*.jdk"),("All Files", "*.*")),title=t, initialdir=os.path.expanduser('~\Documents'))
else:
FFile= askopenfilename(filetypes=(("jdk file", "*.jdk"),("All Files", "*.*")),title=t)
sys.path.append(marsDllPath)
a = clr.AddReference('MatlabFunctions')
aObj = a.CreateInstance('Example.MatlabFunctions.MatLabFunctions')
Run Code Online (Sandbox Code Playgroud)
编辑:似乎与pythonnet"imoprt clr"相关的问题,但我确实在代码中需要它.
tk-toolkit ×10
tkinter ×7
python ×6
tcl ×3
python-3.x ×2
.net ×1
histogram ×1
menu ×1
pdf ×1
perl ×1
perltk ×1
python.net ×1
r ×1
radio-button ×1
ruby ×1
slider ×1
ubuntu ×1
ubuntu-unity ×1
view ×1