我正在使用python 2.7.2和Windows 7.我搜索了互联网,帮助和其他来源,但我找不到我的问题的答案.
我的一个源导入tkinter,这个导入_tkinter.这时它说ImportError DLL load failed:
Traceback (most recent call last): File "NERO/show_image.py", line 13,
in <module> import Tkinter File "C:\Python27\lib\lib-tk\Tkinter.py", line 38,
in <module> import FixTk File "C:\Python27\lib\lib-tk\FixTk.py", line 65,
in <module> import _tkinter ImportError: DLL load failed: %1 is not a valid Win32 application.
2012-Jan-04 12:27:21.889374 (M) [python] Finished process
Run Code Online (Sandbox Code Playgroud)
我搜索了_tkinter,我发现它在Python27/libs中作为lib文件.
在许多网站上它说安装tk/tcl或tkinter,但我找不到单独的Windows安装.
使用http://www.python.org/getit/releases/2.7/中的 Windows x86 MSI安装程序(2.7).在Windows 7 64位.python版本是32位.
我试图清除tkinter中的一个帧,以便可以写入新内容(刷新信息),但我无法做到.我知道这些
frame.destroy()
frame.pack_forget()
frame.grid_forget()
Run Code Online (Sandbox Code Playgroud)
但frame.destroy()将完全删除框架.而另外两个也无法给我我想要的结果.我需要的只是清理框架中的每个项目,但框架本身将保留.无论如何要做到这一点?
我需要一个使用Tkinter模块创建静态(不可调整大小)窗口的Python脚本.
我有一个非常简单的Tkinter脚本,但我不希望它可以调整大小.如何防止Tkinter窗口可调整大小?老实说,我不知道该怎么做.
这是我的脚本:
from tkinter import *
import ctypes, os
def callback():
active.set(False)
quitButton.destroy()
JustGo = Button(root, text=" Keep Going!", command= lambda: KeepGoing())
JustGo.pack()
JustGo.place(x=150, y=110)
#root.destroy() # Uncomment this to close the window
def sleep():
if not active.get(): return
root.after(1000, sleep)
timeLeft.set(timeLeft.get()-1)
timeOutLabel['text'] = "Time Left: " + str(timeLeft.get()) #Update the label
if timeLeft.get() == 0: #sleep if timeLeft = 0
os.system("Powercfg -H OFF")
os.system("rundll32.exe powrprof.dll,SetSuspendState 0,1,0")
def KeepGoing():
active.set(True)
sleep()
quitButton1 = Button(root, text="do not sleep!", command=callback)
quitButton1.pack() …Run Code Online (Sandbox Code Playgroud) 我已经看到了两种设置tkinter程序的基本方法.有没有理由更喜欢一个到另一个?
from Tkinter import *
class Application():
def __init__(self, root, title):
self.root = root
self.root.title(title)
self.label = Label(self.root, text='Hello')
self.label.grid(row=0, column=0)
root = Tk()
app = Application(root, 'Sample App')
root.mainloop()
Run Code Online (Sandbox Code Playgroud)
和
from Tkinter import *
class Application(Frame):
def __init__(self, title, master=None):
Frame.__init__(self, master)
self.grid()
self.master.title(title)
self.label = Label(self, text='Hello')
self.label.grid(row=0, column=0)
app = Application('Sample App')
app.mainloop()
Run Code Online (Sandbox Code Playgroud) 我想在使用该urllib.urlretrive方法从Web下载文件时显示进度条.
我如何使用它ttk.Progressbar来执行此任务?
这是我到目前为止所做的:
from tkinter import ttk
from tkinter import *
root = Tk()
pb = ttk.Progressbar(root, orient="horizontal", length=200, mode="determinate")
pb.pack()
pb.start()
root.mainloop()
Run Code Online (Sandbox Code Playgroud)
但它只是不断循环.
我有这个可滚动的框架(实际上是画布内的框架).
import Tkinter as tk
class Scrollbarframe():
def __init__(self, parent,xsize,ysize,xcod,ycod):
def ScrollAll(event):
canvas1.configure(scrollregion=canvas1.bbox("all"),width=xsize,height=ysize,bg='white')
self.parent=parent
self.frame1=tk.Frame(parent,bg='white')
self.frame1.place(x=xcod,y=ycod)
canvas1=tk.Canvas(self.frame1)
self.frame2=tk.Frame(canvas1,bg='white',relief='groove',bd=1,width=1230,height=430)
scrollbar1=tk.Scrollbar(self.frame1,orient="vertical",command=canvas1.yview)
canvas1.configure(yscrollcommand=scrollbar1.set)
scrollbar1.pack(side="right",fill="y")
canvas1.pack(side="left")
canvas1.create_window((0,0),window=self.frame2,anchor='nw')
self.frame2.bind("<Configure>",ScrollAll)
Run Code Online (Sandbox Code Playgroud)
我想将鼠标滚轮绑定到滚动条,以便用户可以向下滚动框架,而无需使用滚动条上的箭头按钮.环顾四周后,我添加了一个canvas1像我这样的绑定
self.frame1.bind("<MouseWheel>", self.OnMouseWheel)
Run Code Online (Sandbox Code Playgroud)
这是功能:
def OnMouseWheel(self,event):
self.scrollbar1.yview("scroll",event.delta,"units")
return "break"
Run Code Online (Sandbox Code Playgroud)
但是当我使用鼠标滚轮时,滚动条不会移动.谁能帮我这个?我想要的只是当用户使用鼠标滚轮(在框架区域内/滚动条上)时,画布应自动向上或向下滚动.
我在安装tkinter期间遇到了问题.我有2.7.11版.我输入了pip install tkinterdos,但它显示以下消息:
收集tkinter
找不到满足要求的版本tkinter(来自版本:)没有为tkinter找到匹配的分发
我已经使用相同的程序成功安装了烧瓶,但是对于tkinter来说它显示出问题.我该怎样摆脱这个问题?
所以我试图使用Axes对象来控制我的matlibplot数字.我不使用PLT(又名进口matlibplot.pyplot如PLT),因为我在嵌入我的每Tkinter的GUI图形此.
但是,我也在使用图中的子图,所以类似于:
a = f.add_subplot(121)
a2 = f.add_subplot(122)
a.plot(fn2,mag)
a2.bar(range(0,10), magBin, width)
Run Code Online (Sandbox Code Playgroud)
这一切都很好,我可以使用轴属性来控制事物(ieaaxesMethod()),但我想要我的条形图的字符串标签,按此,请参阅代码.
我的困境是我无法使用
plt.xticks(ind+width, ('G1', 'G2', 'G3', 'G4', 'G5') )
Run Code Online (Sandbox Code Playgroud)
如在示例中,因为如果我想将它嵌入到我的tkinter gui中,我就不能使用plt.我只能使用Axes对象做什么.我正在尝试使用a2.set_xticks,但这不允许字符串作为我的条形图所需的刻度功能.
在这方面的任何帮助将是惊人的!
泰勒
我正在TKinterUbuntu上编写一个Python程序来导入和打印Textwidget中特定文件夹中的文件名.它只是将文件名添加到Text
窗口小部件中的先前电影名称,但我想首先清除它,然后添加一个新的文件名列表.但我正在努力清除Text小部件以前的文件名列表.
有人可以解释如何清除Text小部件吗?
屏幕截图和编码如下:
import os
from Tkinter import *
def viewFile():
path = os.path.expanduser("~/python")
for f in os.listdir(path):
tex.insert(END, f + "\n")
if __name__ == '__main__':
root = Tk()
step= root.attributes('-fullscreen', True)
step = LabelFrame(root, text="FILE MANAGER", font="Arial 20 bold italic")
step.grid(row=0, columnspan=7, sticky='W', padx=100, pady=5, ipadx=130, ipady=25)
Button(step, text="File View", font="Arial 8 bold italic", activebackground=
"turquoise", width=30, height=5, command=viewFile).grid(row=1, column=2)
Button(step, text="Quit", font="Arial 8 bold italic", activebackground=
"turquoise", width=20, …Run Code Online (Sandbox Code Playgroud) tkinter ×10
python ×9
binding ×1
frame ×1
matplotlib ×1
module ×1
mousewheel ×1
python-3.x ×1
scrollbar ×1
static ×1
text-widget ×1
ttk ×1
windows ×1