本文整理汇总了Python中ttk.Button.winfo_width方法的典型用法代码示例。如果您正苦于以下问题:Python Button.winfo_width方法的具体用法?Python Button.winfo_width怎么用?Python Button.winfo_width使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ttk.Button
的用法示例。
在下文中一共展示了Button.winfo_width方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Application
# 需要导入模块: from ttk import Button [as 别名]
# 或者: from ttk.Button import winfo_width [as 别名]
class Application(Frame):
def __init__(self, master=None):
Frame.__init__(self, master)
self.pack(fill=BOTH, expand=1)
self.initUI()
self.setGeometry()
self.component = NewComponent()
def setGeometry(self):
x = 300
y = 100
self.master.geometry("400x300+%d+%d" % (x, y))
self.master.update()
def initUI(self):
#setup title
self.master.title("Component Creator")
self.style = Style()
self.style.theme_use("clam")
#indicator label
self.labelName = Label(self, text="Component Name:")
self.labelName.place(x=10, y=10)
self.master.update()
# create variable and namefield for input of component name
sv = StringVar()
sv.trace("w", lambda name, index, mode, sv=sv: self.nameChanged(sv))
self.nameField = Entry(self, textvariable=sv)
self.nameField.place(x=10+self.labelName.winfo_width() + 10, y=10)
self.master.update()
# label for image name that will show img name for a given component name
self.imgNameVar = StringVar()
self.imgNameVar.set('imageName:')
self.labelImageName = Label(self, textvariable=self.imgNameVar)
self.labelImageName.place(x=10+self.labelName.winfo_width()+10,y=40)
# checkbox for visible component or not
self.cbVar = IntVar()
self.cb = Checkbutton(self, text="Visible Component", variable=self.cbVar)
self.cb.place(x=10, y=70)
# dropdown list for category
self.labelCategory = Label(self, text="Category:")
self.labelCategory.place(x=10, y=110)
self.master.update()
acts = ['UserInterface', 'Layout', 'Media', 'Animation', 'Sensors', 'Social', 'Storage',
'Connectivity', 'LegoMindStorms', 'Experimental', 'Internal', 'Uninitialized']
self.catBox = Combobox(self, values=acts)
self.catBox.place(x=10+self.labelCategory.winfo_width()+10, y=110)
# button to select icon image
self.getImageButton = Button(self, text="Select icon", command=self.getImage)
self.getImageButton.place(x=10, y=150)
self.master.update()
# explanation for resizing
self.resizeVar = IntVar()
self.resizeCB = Checkbutton(self,
text="ON=Resize Image (Requires PIL)\nOFF=Provide 16x16 Image", variable=self.resizeVar)
self.resizeCB.place(x=10+self.getImageButton.winfo_width()+10, y=150)
# create button
self.createButton = Button(self, text="Create", command=self.create)
self.createButton.place(x=10, y=230)
#cancel button
self.cancelButton = Button(self, text="Cancel", command=self.quit)
self.cancelButton.place(x=200, y=230)
# open file picker for selecting an icon
def getImage(self):
ftypes = [('All Picture Files', ('*.jpg', '*.png', '*.jpeg', '*.bmp')), ('All files', '*')]
self.component.imgFile = askopenfilename(filetypes=ftypes, title="Select an Icon file")
# update component name and image name for component by lowercasing first letter
def nameChanged(self, sv):
s = sv.get()
self.component.compName = s
self.component.compImgName = s[:1].lower() + s[1:] if s else ''
self.imgNameVar.set('imageName: %s' % self.component.compImgName)
# tries to create component
def create(self):
# sets parameters for new component based on input values
self.component.visibleComponent = bool(self.cbVar.get())
self.component.resizeImage = bool(self.resizeVar.get())
self.component.category = self.catBox.get().upper()
self.component.compName = self.nameField.get()
try:
# check if component already exists
try:
open('../../components/src/com/google/appinentor/components/runtime/%s.java', 'r')
tkMessageBox.showerror("Duplicate Component","%s already exists" % self.component.compName)
#.........这里部分代码省略.........