我一直收到错误:
_tkinter.TclError:未知选项"-menu"
我的MWE看起来像:
from tkinter import *
def hello():
print("hello!")
class Application(Frame):
def createWidgets(self):
self.menuBar = Menu(master=self)
self.filemenu = Menu(self.menuBar, tearoff=0)
self.filemenu.add_command(label="Hello!", command=hello)
self.filemenu.add_command(label="Quit!", command=self.quit)
def __init__(self, master):
Frame.__init__(self, master)
self.pack()
self.createWidgets()
self.config(menu=self.menuBar)
if __name__ == "__main__":
root = Tk()
ui = Application(root)
ui.mainloop()
Run Code Online (Sandbox Code Playgroud)
我在OS X 10.8上使用python 3.为什么我收到未知选项错误?
只需单击一个按钮即可运行该程序.我试图使该按钮在被点击时被禁用,并在5秒后激活,同时不干扰程序的其余部分.(程序的其余部分在代码中称为#这里其余的程序运行)
import time
from tkinter import Tk, Button, SUNKEN, RAISED
from threading import Thread
def tFunc(button):
thread = Thread(target= buttonDisable, args=(button))
thread.start()
# here the rest of the program runs
def buttonDisable(button):
button.config(state='disable',relief=SUNKEN)
time.sleep(5)
button.config(state='active', relief=RAISED)
root = Tk()
button = Button(root, text='Button', command= lambda : tFunc(button))
button.pack()
root.mainloop()
Run Code Online (Sandbox Code Playgroud)
但是我收到以下错误:
Exception in thread Thread-1:
Traceback (most recent call last):
File "C:\Python33\lib\threading.py", line 637, in _bootstrap_inner
self.run()
File "C:\Python33\lib\threading.py", line 594, in run
self._target(*self._args, **self._kwargs)
TypeError: buttonDisable() argument after * must …Run Code Online (Sandbox Code Playgroud) 我正在使用Python3,当我们按下登录按钮时,我试图将用户在用户名和密码框中键入的内容传递给登录功能.登录功能只需将用户名标签打包到GUI上即可.
码:
import tkinter
from tkinter import *
import sys
def login_gui():
global login_window
global studentid_entry_login
usr_login = StringVar()
pwd_login = StringVar()
login_window=tkinter.Tk()
login_window.title("Login")
login_window.geometry("200x200+500+300")
username_label_login = tkinter.Label(login_window, text="Username:").pack()
username_entry_login = tkinter.Entry(login_window, textvariable=usr_login).pack()
password_label_login = tkinter.Label(login_window, text="\nPassword:").pack()
password_entry_login = tkinter.Entry(login_window, textvariable=pwd_login).pack()
button_login = tkinter.Button(login_window, text="Login", command = login).pack()
login_window.mainloop()
def login():
username = usr_login.get()
label1 = tkinter.Label(login_window, text=username).pack()
return
login_gui()
Run Code Online (Sandbox Code Playgroud)
追溯:
Traceback (most recent call last):
File "C:/Python33/Folder/tkinter-test.py", line 25, in <module>
login_gui()
File "C:/Python33/Folder/tkinter-test.py", line 8, in login_gui
usr_login …Run Code Online (Sandbox Code Playgroud) 我正在研究“密码生成器”,它将生成一串随机字符。我想添加一个“复制”按钮,单击该按钮将获取该随机字符串并将其添加到剪贴板,以便可以将其粘贴到其他位置。
我以为我已经用当前的代码解决了这个问题,因为我不再收到错误消息,但是每当我尝试粘贴密码时,我都会得到类似“ < function genpass at 0x029BA5F0 >”的信息。
import random
from swampy.Gui import *
from Tkinter import *
import string
#--------Globals-------
pcha = string.ascii_letters + string.punctuation + string.digits
g = Gui()
#--------Defs---------
def genpass():
return "".join(random.choice(pcha) for i in range (10))
def close():
g.destroy()
def copy():
g.withdraw()
g.clipboard_clear()
g.clipboard_append(genpass)
#--------GUI----------
g.title("Password Helper")
g.la(text="Welcome to Password Helper! \n \n Choose from the options below to continue. \n")
rndpass = StringVar()
update = lambda:rndpass.set(genpass())
btna = g.bu(text="Generate a New Password", command=update)
btna.pack(padx=5) …Run Code Online (Sandbox Code Playgroud) 下面的代码是计算我正在进行的纸牌游戏得分手的积分.我的问题与我的Round_Points函数中的if/elif语句有关.每当我运行代码时,Trick_Base仅从最后的else语句设置为878(我选择测试的随机数),即使我在GUI中为Tricks_Bid输入6到10之间的值(我正在使用tkinter) Python 3.4).我是否需要添加一些内容以确保将Trick_Base设置为if语句中的适当值?或者我的条目小部件中有什么东西可以关闭吗?到目前为止,我搜索过的任何内容都没有给我任何关于错误的线索.在此先感谢您的任何帮助或建议!
PS:我的代码基于这个示例计算器:http ://www.tkdocs.com/tutorial/firstexample.html当我开始添加if和elif语句时,问题就开始了.
from tkinter import *
from tkinter import ttk
def Round_Points():
if Tricks_Bid == 10:
Trick_Base = 400
elif Tricks_Bid == 9:
Trick_Base = 300
elif Tricks_Bid == 8:
Trick_Base= 200
elif Tricks_Bid == 7:
Trick_Base = 100
elif Tricks_Bid == 6:
Trick_Base = 90
else:
Trick_Base=878
global Suit_Base
Points.set(Trick_Base+Suit_Base)
root = Tk()
root.title("Tricks")
mainframe = ttk.Frame(root, padding="3 3 12 12")
mainframe.grid(column=0, row=0, sticky=(N, W, E, S))
mainframe.columnconfigure(0, weight=1)
mainframe.rowconfigure(0, weight=1)
Points = IntVar()
Suit_Base …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用tkinter制作GUI.我怎样才能有3个树视图 - 两个在顶部并排,第三个在底部的两个树视图下方的底部.我设法得到了2个并排.我提供了前两个的左边值,但当我使用底部的第三个时,它出现在前两个树视图的中间.
container = ttk.Frame()
container.pack(fill='both', expand=True, side=side)
self.tree = ttk.Treeview()
Run Code Online (Sandbox Code Playgroud)
谢谢您的帮助
晚上好,
我有一个事件,Button1,绑定到一个图像,使其可以点击.单击它后,它将转到一个函数.但是,我需要事件同时转到2个不同的功能.事件一次使用1个函数(两个工作但不在一起)所以我认为我只是格式化事件错误.
self.img_list[2].bind('<Button-1>', removewidgetsHome)
Run Code Online (Sandbox Code Playgroud)
我试过了:
self.img_list[2].bind('<Button-1>', removewidgetsHome, feedbackpage)
Run Code Online (Sandbox Code Playgroud)
但无济于事.
对于那些感兴趣的人是我的完整代码
我正在尝试使用after_cancel来停止简单图像查看器中的动画循环.我已经阅读了关于Tcl的文档,在这里搜索并google,并探索了python subreddits.我的错误是:
TclError: wrong # args: should be "after cancel id|command"
Run Code Online (Sandbox Code Playgroud)
这发生在以下代码的最后一行(请不要因为使用全局变量而杀了我,这个项目只是一个图像查看器来显示我们办公室的天气预报产品):
n_images = 2
images = [PhotoImage(file="filename"+str(i)+".gif") for i in range(n_images)]
current_image = -1
def change_image():
displayFrame.delete('Animate')
displayFrame.create_image(0,0, anchor=NW,
image=images[current_image], tag='Animate')
displayFrame.update_idletasks() #Force redraw
callback = None
def animate():
forward()
callback = root.after(1000, animate)
def forward():
global current_image
current_image += 1
if current_image >= n_images:
current_image = 0
change_image()
def back():
global current_image
current_image -= 1
if current_image < 0:
current_image = n_images-1
change_image()
def stop():
root.after_cancel(callback)
Run Code Online (Sandbox Code Playgroud)
如果有更合适的方法来停止Tkinter中的动画循环,请告诉我!
我正在使用tkinter进行数学测试.我有4个条目允许用户输入问题的答案.答案必须是整数格式,否则会产生很长的错误.我希望我的程序检查输入的值是否为整数.然后如果它不是整数,则打开一个消息框,告诉用户检查答案.
这是我的代码:(这是一个很长的代码,因为我不知道如何缩短它,我不是程序员)
from tkinter import*
from tkinter import messagebox
from random import*
n1= randint(1,6)
n2= randint(1,9)
ques1 = n1, "x", n2, "="
c1= n1*n2
n1= randint(8,15)
n2= randint(1,7)
ques2 = n1, "-", n2, "="
c2= n1-n2
n1= randint(1,10)
n2= randint(5,15)
ques3 = n1, "+", n2, "="
c3= n1+n2
n1= randint(5,12)
n2= randint(1,10)
ques4 = n1, "x", n2, "="
c4= n1*n2
#window
window = Tk()
window.geometry("280x450")
window.title("quiz")
window.configure(background='yellow')
def checkthrough():
if ans1.get() == '':
messagebox.showinfo("error", "check again ")
elif ans2.get() == …Run Code Online (Sandbox Code Playgroud) 我试图制作一个按钮,当点击时更新标签上的数字.我想要实现的是,当有人进球时,你可以点击目标!按钮,它将更新团队得分.
import sys
from tkinter import *
root = Tk()
class team1:
score = 0
def goal(self):
self.score += 1
team1_attempt.set(text = self.score)
team1 = team1()
team1_attempt = Label(text = team1.score).pack()
team1_button = Button(text="Goal!", command = team1.goal).pack()
Run Code Online (Sandbox Code Playgroud)
希望有人可以帮忙!python新手.
python ×10
tkinter ×10
python-3.x ×3
function ×2
class ×1
clipboard ×1
events ×1
if-statement ×1
integer ×1
login ×1
parameters ×1
pillow ×1
python-2.7 ×1
python-3.4 ×1
string ×1
treeview ×1
ttk ×1