예제 #1
0
 def __init__(self, parent=None, **options):
     Frame.__init__(self, parent, **options)
     self.pack()
     Label(self, text='Basic Demos').pack()
     for (key, value) in demos.items():
         # Button(self,text=key,command=value).pack(side=TOP,fill=BOTH)
         func = (lambda key=key: self.printit(key))
         Button(self, text=key, command=func).pack(side=TOP, fill=BOTH)
     Quitter(self).pack(side=TOP, fill=BOTH)
예제 #2
0
파일: tk3.py 프로젝트: shudd23/python-labs
 def __init__(self, parent=None, file=None):
     frm = Frame(parent)
     frm.pack(fill=X)
     Button(frm, text='Save', command=self.onSave).pack(side=LEFT)
     Button(frm, text='Cut', command=self.onCut).pack(side=LEFT)
     Button(frm, text='Paste', command=self.onPaste).pack(side=LEFT)
     Button(frm, text='Find', command=self.onFind).pack(side=LEFT)
     Quitter(frm).pack(side=LEFT)
     ScrolledText.__init__(self, parent, file=file)
     self.text.config(font=('courier', 12, 'normal'))
예제 #3
0
 def __init__(self, parent=None, **options):
     Frame.__init__(self, parent, **options)
     self.pack()
     Label(self, text='Radio Demos').pack(side=TOP)
     self.var = StringVar()
     # 为了确保是单选,需要给每个Radiobutton分配统一的variable,不同的value
     for key in demos:
         Radiobutton(self, text=key, command=self.onPress,
                     variable=self.var, value=key).pack(anchor=NW)
     self.var.set(key)
     Button(self, text='State', command=self.report).pack(fill=X)
     Quitter(self).pack(fill=X)
예제 #4
0
def variables_form_layout():
    from tk2_quitter import Quitter
    fields = 'Name', 'Job', 'Pay', 'Value', 'Address'

    def fetch(variables):
        for variable in variables:
            print('Input => "%s"' % variable.get())

    def makeform(root, fields):
        form = Frame(root)
        left = Frame(form)
        right = Frame(form)
        form.pack(fill=X)
        left.pack(side=LEFT)
        right.pack(side=RIGHT, expand=YES, fill=X)

        variables = []
        for field in fields:
            # Label和Entry没有关联起来,所以它们可能没对齐
            lab = Label(left, width=8, text=field)
            ent = Entry(right)
            lab.pack(side=TOP)
            ent.pack(side=TOP, fill=X)
            var = StringVar()
            ent.config(textvariable=var)
            var.set('enter here')
            variables.append(var)
        return variables

    def show(variables, popup):
        popup.destroy()
        # 使用StringVar,在窗口销毁之后也可以获取数据
        fetch(variables)

    # 显示模态输入表单
    def ask():
        popup = Toplevel()
        vars = makeform(popup, fields)
        Button(popup, text='OK', command=(lambda: show(vars, popup))).pack()
        popup.grab_set()
        popup.focus_get()
        popup.wait_window()

    root = Tk()
    vars = makeform(root, fields)
    Button(root, text='Fetch', command=(lambda: fetch(vars))).pack(side=LEFT)
    Button(root, text='Popup', command=ask).pack(side=RIGHT)
    Quitter(root).pack(side=RIGHT)
    root.bind('<Return>', (lambda event: fetch(vars)))
    root.mainloop()
예제 #5
0
def quit_button():
    from tkMessageBox import askokcancel

    class Quitter(Frame):
        def __init__(self, parent=None):
            Frame.__init__(self, parent)
            self.pack()
            widget = Button(self, text='Quit', command=self.quit)
            widget.pack(side=LEFT, expand=YES, fill=BOTH)

        def quit(self):
            ans = askokcancel('Verify exit', 'Really quit?')
            if ans:
                Frame.quit(self)

    Quitter().mainloop()
예제 #6
0
 def __init__(self, parent=None, **options):
     Frame.__init__(self, parent, **options)
     self.pack()
     Label(self, text='Scale Demos').pack()
     self.var = IntVar()
     Scale(self, label='Pick demo number A',
           command=self.onMove, variable=self.var,
           from_=0, to=len(demos)-1).pack()
     Scale(self, label='Pick demo number B',
           command=self.onMove, variable=self.var,
           from_=0, to=len(demos)-1,
           length=200, tickinterval=1,
           showvalue=YES, orient='horizontal').pack()
     Quitter(self).pack(side=RIGHT)
     Button(self, text='Run demo', command=self.onRun).pack(side=LEFT)
     Button(self, text='State', command=self.report).pack(side=RIGHT)
예제 #7
0
def simple_entry():
    from tk2_quitter import Quitter

    def fetch():
        print('Input => "%s"' % ent.get())
        # ent.config(state=DISABLED)

    root = Tk()
    ent = Entry(root)
    ent.delete(0, END)
    ent.insert(0, 'Type words here')
    ent.pack(side=TOP, fill=X)

    ent.focus()
    ent.bind('<Return>', (lambda event: fetch()))  # 绑定回车键事件
    btn = Button(root, text='Fetch', command=fetch)
    btn.pack(side=LEFT)
    Quitter(root).pack(side=RIGHT)
    root.mainloop()
예제 #8
0
def button_bars_demo():
    root = Tk()
    lng = Checkbar(root, ['Python', 'C#', 'Java', 'C++'])
    gui = Radiobar(root, ['win', 'x11', 'mac'], side=TOP, anchor=NW)
    tgl = Checkbar(root, ['All'])

    gui.pack(side=LEFT, fill=Y)
    lng.pack(side=TOP, fill=X)
    tgl.pack(side=LEFT)

    lng.config(relief=GROOVE, bd=2)
    gui.config(relief=RIDGE, bd=2)

    def allstates():
        print(gui.state(), lng.state(), tgl.state())

    from tk2_quitter import Quitter
    Quitter(root).pack(side=RIGHT)
    Button(root, text='Peek', command=allstates).pack(side=RIGHT)
    root.mainloop()
예제 #9
0
def entry_form_layout():
    from tk2_quitter import Quitter
    fields = 'Name', 'Job', 'Pay'

    def fetch(entries):
        for entry in entries:
            print('Input => "%s"' % entry.get())

    def makeform(root, fields):
        entries = []
        for field in fields:
            row = Frame(root)
            lab = Label(row, width=5, text=field)
            ent = Entry(row)
            row.pack(side=TOP, fill=X)
            lab.pack(side=LEFT)
            ent.pack(side=RIGHT, expand=YES, fill=X)
            entries.append(ent)
        return entries

    def show(entries, popup):
        # 必须在弹出窗口销毁之前收集数据
        fetch(entries)
        popup.destroy()

    # 显示模态输入表单
    def ask():
        popup = Toplevel()
        ents = makeform(popup, fields)
        Button(popup, text='OK', command=(lambda: show(ents, popup))).pack()
        popup.grab_set()
        popup.focus_get()
        popup.wait_window()

    root = Tk()
    ents = makeform(root, fields)
    root.bind('<Return>', (lambda event: fetch(ents)))
    Button(root, text='Fetch', command=(lambda: fetch(ents))).pack(side=LEFT)
    Button(root, text='Popup', command=ask).pack(side=RIGHT)
    Quitter(root).pack(side=RIGHT)
    root.mainloop()
예제 #10
0
 def tools(self):
     frm = Frame(self)
     frm.pack(side=RIGHT)
     Button(frm, text='State', command=self.report).pack(fill=X)
     Quitter(frm).pack(fill=X)