我想学一点tkinter。我在Youtube上看了sentdex的几本指南,觉得自己对基础知识有很好的理解。但是,现在我正在尝试编写一个脚本,它可以作为快速日志使用,并且在从entry/text/optionmenu获取文本时遇到了问题。
如果我在课外设置gui,我可以简单地做一个variable.get(),一切都是达克。但是当我在一个类中有gui tkinter的东西时,我得到了一个未定义的异常。
这是我的密码。问题在于def saveButtonCommand(self):
我如何获得的值的注意文本和officeOption/Var?
# Imports
from tkinter import *
from tkinter import messagebox
import sys, datetime
class Window(Frame):
def __init__(self, master = None):
Frame.__init__(self, master)
self.master = master
self.init_window()
def init_window(self):
self.master.title("SPL - " + str(datetime.date.today()))
self.configure(background="#e7e7e7")
self.pack(fill=BOTH, expand=1)
# Menu -> Quit, Open Log
menu = Menu(self.master)
self.master.config(menu=menu)
file = Menu(menu)
file.add_command(label="Open Log")
file.add_command(label="Quit", command=self.client_exit)
menu.add_cascade(label="File", menu=file)
# Window Items
# Office Drop Down
OFFICES = [
"County Building",
"Adult Probation",
"Building & Zoning",
"Circuit Court",
" - CC. Family Division",
" - CC. Friend of the Court",
" - CC. Juvenile Division",
"Clerk",
"Commissioners",
"Computer Infomration Systems",
"Corporation Counsel",
"District Court",
" - DC. Community Corrections",
" - DC. Magistrate Office",
" - DC. Probation Office",
"Economic Development Corp.",
"Equalization",
"Maintenance",
"Probate Court",
"Prosecuting Attorney",
"Public Guardian",
"Register of Deeds",
"Sheriff Department",
" - SD. Booking",
" - SD. Kitchen",
" - SD. Records",
" - SD. Squadroom",
"Social Security",
"Tax Mapping/GIS",
"Treasurer",
"Veteran's"
]
officeLabel = Label(self, text="Office:", fg="#000000", bg="#e7e7e7", font="Verdana 10")
officeLabel.place(x=5,y=5)
officeOptionVar = StringVar()
officeOptionVar.set(OFFICES[0]) # Default Value
officeOption = OptionMenu(self, officeOptionVar, *OFFICES)
officeOption.place(x=5,y=28,width=310)
# Note
noteLabel = Label(self, text="Note:", fg="#000000", bg="#e7e7e7", font="Verdana 10")
noteLabel.place(x=5,y=58)
noteText = Text()
noteText.place(x=5, y=81, width=310, height=225)
# Save Button
saveButton = Button(self, text='Save', command=self.saveButtonCommand)
saveButton.place(x=5, y=312, width=310, height=50)
def client_exit(self):
exit()
def saveButtonCommand(self):
office = officeOptionVar.get()
note = noteText.get("1.0","end-1c")
messagebox.showinfo(title="Test", message=note)
root = Tk()
root.resizable(0,0)
screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()
geo_width = 320
geo_height = 370
geo_offset_w = int((screen_width/2)-(geo_width/2))
root.geometry(str(geo_width) + "x" + str(geo_height) + "+" + str(geo_offset_w) + "+200")
app = Window(root)
root.mainloop()
我已经修好了,你应该用self。“变量名”来声明可访问的属性。
from tkinter import *
from tkinter import messagebox
import sys, datetime
class Window(Frame):
def __init__(self, master = None):
Frame.__init__(self, master)
self.master = master
self.init_window()
def init_window(self):
self.master.title("SPL - " + str(datetime.date.today()))
self.configure(background="#e7e7e7")
self.pack(fill=BOTH, expand=1)
# Menu -> Quit, Open Log
menu = Menu(self.master)
self.master.config(menu=menu)
file = Menu(menu)
file.add_command(label="Open Log")
file.add_command(label="Quit", command=self.client_exit)
menu.add_cascade(label="File", menu=file)
# Window Items
# Office Drop Down
OFFICES = [
"County Building",
"Adult Probation",
"Building & Zoning",
"Circuit Court",
" - CC. Family Division",
" - CC. Friend of the Court",
" - CC. Juvenile Division",
"Clerk",
"Commissioners",
"Computer Infomration Systems",
"Corporation Counsel",
"District Court",
" - DC. Community Corrections",
" - DC. Magistrate Office",
" - DC. Probation Office",
"Economic Development Corp.",
"Equalization",
"Maintenance",
"Probate Court",
"Prosecuting Attorney",
"Public Guardian",
"Register of Deeds",
"Sheriff Department",
" - SD. Booking",
" - SD. Kitchen",
" - SD. Records",
" - SD. Squadroom",
"Social Security",
"Tax Mapping/GIS",
"Treasurer",
"Veteran's"
]
officeLabel = Label(self, text="Office:", fg="#000000", bg="#e7e7e7", font="Verdana 10")
officeLabel.place(x=5,y=5)
self.officeOptionVar = StringVar()
self.officeOptionVar.set(OFFICES[0]) # Default Value
officeOption = OptionMenu(self, self.officeOptionVar, *OFFICES)
officeOption.place(x=5,y=28,width=310)
# Note
noteLabel = Label(self, text="Note:", fg="#000000", bg="#e7e7e7", font="Verdana 10")
noteLabel.place(x=5,y=58)
self.noteText = Text()
self.noteText.place(x=5, y=81, width=310, height=225)
# Save Button
saveButton = Button(self, text='Save', command=self.saveButtonCommand)
saveButton.place(x=5, y=312, width=310, height=50)
def client_exit(self):
exit()
def saveButtonCommand(self):
office = self.officeOptionVar.get()
note = self.noteText.get("1.0","end-1c")
messagebox.showinfo(title="Test", message=note)
root = Tk()
root.resizable(0,0)
screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()
geo_width = 320
geo_height = 370
geo_offset_w = int((screen_width/2)-(geo_width/2))
root.geometry(str(geo_width) + "x" + str(geo_height) + "+" + str(geo_offset_w) + "+200")
app = Window(root)
root.mainloop()
公共类DbHelper扩展了SQLiteOpenHelper{ }
我想在UTC中获取java的当前时间: 所以,我现在在维也纳,当前当地时间是16:30:29,当前与UTC的偏移量是2小时,我想得到 结尾有这个Z(表示“祖鲁时间”)。 用这个 我得到 如何消除微秒? 我也尝试了,但在最后我无法获得Z。
我在我的项目中使用了Java、Wildfly18、Primefaces和JSF,但是我得到了这个警告!有人知道为什么我只在Firefox中使用这个项目时会收到这个警告吗? 任何信息都会有帮助。以下是服务器日志: 17:13:41,238警告[javax.enterprise.resource.webcontainer.jsf.application](默认任务-291)JSF1064:Ressou
在我的spring项目中,我可以像这样用XML定义bean:
当存在依赖关系时,在ivy.xml中定义,例如: 在构建中.xml,我让常春藤检索它。然后,它会下载一个名称中包含版本 ID 的文件。例如,库/我的包-6.0.0.zip 我如何知道版本(6.0.0)或我的ANT构建中的全名,而不用手动/去重复ivy.xml中的版本? 我希望能够做这样的事情: