当前位置: 首页>>代码示例>>Python>>正文


Python Entry.focus_set方法代码示例

本文整理汇总了Python中ttk.Entry.focus_set方法的典型用法代码示例。如果您正苦于以下问题:Python Entry.focus_set方法的具体用法?Python Entry.focus_set怎么用?Python Entry.focus_set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ttk.Entry的用法示例。


在下文中一共展示了Entry.focus_set方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Calculator

# 需要导入模块: from ttk import Entry [as 别名]
# 或者: from ttk.Entry import focus_set [as 别名]
class Calculator(Frame):

    def __init__(self,parent):
        Frame.__init__(self,parent)
        self.parent = parent
        self.initUI()
        self.string = ""

    def initUI(self):
        self.parent.title("Calculator")
        Style().configure("TButton",padding = (0,5,0,5),font = 'serif 10')
        self.data = StringVar()
        self.columnconfigure(0,pad = 4)
        self.columnconfigure(1,pad =4)
        self.columnconfigure(2,pad = 4)
        self.columnconfigure(3,pad = 4)

        self.rowconfigure(0,pad = 4)
        self.rowconfigure(1,pad = 4)
        self.rowconfigure(2,pad = 4)
        self.rowconfigure(3,pad = 4)
        self.rowconfigure(4,pad = 4)

        self.entry = Entry(self,textvariable = self.data)
        self.entry.grid(row = 0,columnspan = 4,sticky = W+E)
        self.entry.focus_set()
        
        cls = Button(self,text = 'CLS',command = self.reset())
        cls.grid(row = 1,column = 0)
        bck = Button(self,text = 'Backspace',command = lambda: self.decrement())
        bck.grid(row = 1,column = 1, columnspan = 2,sticky = W+E)
        clo = Button(self,text = 'Close', command = lambda: self.close())
        clo.grid(row = 1,column = 3)
        
        sev = Button(self,text = '7',command = lambda: self.concat('7'))
        sev.grid(row = 2,column = 0)
        eig = Button(self,text = '8',command = lambda: self.concat('8'))
        eig.grid(row = 2,column = 1)
        nin = Button(self,text = '9',command = lambda: self.concat('9'))
        nin.grid(row = 2,column = 2)
        div = Button(self,text = '/',command = lambda: self.addop('/'))
        div.grid(row = 2,column = 3)
        
        fou = Button(self,text = '4',command = lambda: self.concat('4'))
        fou.grid(row = 3,column = 0)
        fiv = Button(self,text = '5',command = lambda: self.concat('5'))
        fiv.grid(row = 3,column = 1)
        six = Button(self,text = '6',command = lambda: self.concat('6'))
        six.grid(row = 3,column = 2)
        mul = Button(self,text = '*',command = lambda: self.addop('*'))
        mul.grid(row = 3,column = 3)
        
        one = Button(self,text = '1',command = lambda: self.concat('1'))
        one.grid(row = 4,column = 0)
        two = Button(self,text = '2',command = lambda: self.concat('2'))
        two.grid(row = 4,column = 1)
        thr = Button(self,text = '3',command = lambda: self.concat('3'))
        thr.grid(row = 4,column = 2)
        mns = Button(self,text = '-',command = lambda: self.addop('-'))
        mns.grid(row = 4,column = 3)
        
        zer = Button(self,text = '0',command = lambda: self.concat('0'))
        zer.grid(row = 5,column = 0)
        dot = Button(self,text = '.',command = lambda: self.concat('.'))
        dot.grid(row = 5,column = 1)
        equ = Button(self,text = '=',command = lambda: self.calculate())
        equ.grid(row = 5,column = 2)
        plu = Button(self,text = '+',command = lambda: self.addop('+'))
        plu.grid(row = 5,column = 3)
        self.pack()

    def addop(self, op):
        if '.' not in str(self.string):
            self.string = str(self.string)+str('.0')+str(op)
        else:
            self.string = str(self.string)+str(op)
        self.data.set(self.string)
        
    def calculate(self):
        self.string = self.data.get()
        self.string = calci(self.string)
        self.data.set(self.string)

    def concat(self,this):
        self.string = str(self.string)+str(this)
        self.data.set(self.string)

    def reset(self):
        self.string = ""
        self.data.set(self.string)

    def decrement(self):
        self.string = str(self.string)[0:len(str(self.string))-1]
        self.data.set(self.string)

    def close(self):
        self.parent.destroy()
开发者ID:RITESHMOHAPATRA,项目名称:Calculator-1,代码行数:99,代码来源:CALCULATOR.py

示例2: NewCustomerDialog

# 需要导入模块: from ttk import Entry [as 别名]
# 或者: from ttk.Entry import focus_set [as 别名]
class NewCustomerDialog(Dialog):
    def __init__(self, master, customers, refresh, edit=False, class_=None, relx=0.5, rely=0.3):
        if edit:
            self.title = "Edit Customer"
        else:
            self.title = "New Customer"

        self.refresh = refresh

        Dialog.__init__(self, master, self.title,
                        class_, relx, rely)
        self.customers = customers

        self.fname = StringVar()
        self.lname = StringVar()
        self.mname = StringVar()
        self.payment = StringVar()
        self.date = StringVar()
        self.close = False

        self.payment.set("Drop In")

        self.edit = edit

        self.new_customer_name = None

    def show(self, line=None):
        '''
        allows preset values
        '''
        self.setup() #base class setup

        self.frame = Frame(self.root)

        # blow out the field every time this is created
        if not self.edit: self.date.set(date.today().strftime("%m/%d/%Y"))
        
        ### dialog content        
        Label(self.frame, text="First Name: ").grid(row=0, sticky=W, ipady=2, pady=2)
        Label(self.frame, text="Middle Initial: ").grid(row=1, sticky=W, ipady=2, pady=2)
        Label(self.frame, text="Last Name: ").grid(row=2, sticky=W, ipady=2, pady=2)
        Label(self.frame, text="Customer Type: ").grid(row=3, sticky=W, ipady=2, pady=2)
        Label(self.frame, text="Date (mm/dd/yyyy): ").grid(row=4, sticky=W, ipady=2, pady=2)

        self.fname_en = Entry(self.frame, width=30, textvariable=self.fname)
        self.mname_en = Entry(self.frame, width=30, textvariable=self.mname)
        self.lname_en = Entry(self.frame, width=30, textvariable=self.lname)
        self.payment_cb = Combobox(self.frame, textvariable=self.payment, width=27,
                                   values=("Drop In", "Punch Card", "Monthly", "Inactive"))
        self.payment_cb.set("Drop In")
        self.date_en = Entry(self.frame, width=30, textvariable=self.date)

        Frame(self.frame, width=5).grid(row=0,column=1,sticky=W)
        
        self.fname_en.grid(row=0,column=2,columnspan=2,sticky=W)
        self.mname_en.grid(row=1,column=2,columnspan=2,sticky=W)
        self.lname_en.grid(row=2,column=2,columnspan=2,sticky=W)
        self.payment_cb.grid(row=3,column=2,columnspan=2,sticky=W)
        self.date_en.grid(row=4,column=2,columnspan=2,sticky=W)
        
        ### buttons
        Button(self.frame, text='Cancel', width=10,
               command=self.wm_delete_window).grid(row=5, column=2, sticky=W, padx=10, pady=3)
        Button(self.frame, text='Submit', width=10,
               command=self.add_customer).grid(row=5, column=3, sticky=W)
        self.frame.pack(padx=10, pady=10)

        self.root.bind("<Return>", self.add_customer)
        self.fname_en.focus_set()

        if line: #preset values
            self.fname.set(line[1])
            self.mname.set(line[2])
            self.lname.set(line[0])
            self.payment_cb.set(line[3])
            self.date.set(line[4].strftime("%m/%d/%Y"))
        
        ### enable from base class
        self.enable()

    def add_customer(self, event=None):
        # validate and show errors
        if self.fname.get() == '':
            showerror("Error!", "First name field blank!")
        elif self.lname.get() == '':
            showerror("Error!", "Last name field blank!")
        elif self.mname.get() == '':
            showerror("Error!", "Middle initial field blank!")
        elif self.payment.get() not in ("Drop In", "Punch Card", "Monthly", "Inactive"):
            showerror("Error!", "Incorect Customer type!")
        elif not re.compile(r'[01]?\d/[0123]?\d/[12]\d{1,3}').search(self.date.get()):
            showerror("Error!", "Bad entry for date, use format mm/dd/yyyy")
        else:
            self.close = True
            
            # do work
            old, row = self.customers.find(str(self.lname.get()).strip(), str(self.fname.get()).strip(),
                                           str(self.mname.get()).strip())
            new = [str(self.lname.get()).strip(), str(self.fname.get()).strip(), str(self.mname.get()).strip(),
                   str(self.payment.get()).strip(), datetime.strptime(self.date.get(), "%m/%d/%Y")]
#.........这里部分代码省略.........
开发者ID:tylerjw,项目名称:jim_tracker,代码行数:103,代码来源:customer.py

示例3: CustomerFrame

# 需要导入模块: from ttk import Entry [as 别名]
# 或者: from ttk.Entry import focus_set [as 别名]
class CustomerFrame(Frame):
    def __init__(self, master, customers, output_text, refresh):
        Frame.__init__(self, master)
        self.output_text = output_text
        self.refresh = refresh
        self.root = master
        self.customers = customers

        self.name = StringVar() #edit customer
        self.names = []
        self.ncd = NewCustomerDialog(self.root, self.customers, self.refresh, edit=True)

        self.fname = StringVar()
        self.lname = StringVar()
        self.mname = StringVar()
        self.payment = StringVar()
        self.date = StringVar()
        self.iconname="New Customer"

        lf = LabelFrame(self, text="New Customer")
        lf.grid(padx=5,pady=5,row=0,column=0,sticky='ew')
        
        ### dialog content        
        Label(lf, text="Name: ").grid(row=0,column=0,sticky='e',padx=(10,0),pady=(10,2))
        Label(lf, text="Type: ").grid(row=1,sticky='e',pady=2,padx=(10,0))
        Label(lf, text="Date: ").grid(row=1,column=2,sticky='e',ipady=2,padx=(10,0))

        self.fname_en = Entry(lf, width=20, textvariable=self.fname)
        self.mname_en = Entry(lf, width=4, textvariable=self.mname)
        self.lname_en = Entry(lf, width=20, textvariable=self.lname)
        self.payment_cb = Combobox(lf, textvariable=self.payment, width=12,
                                   values=("Drop In", "Punch Card", "Monthly", "Inactive"))
        self.date_en = Entry(lf, width=15, textvariable=self.date)
        
        self.fname_en.grid(row=0,column=1,sticky='ew',pady=(10,2))
        self.mname_en.grid(row=0,column=2,sticky='ew',pady=(10,2))
        self.lname_en.grid(row=0,column=3,sticky='ew',padx=(0,10),pady=(10,2))
        self.payment_cb.grid(row=1,column=1,sticky='ew')
        self.date_en.grid(row=1,column=3,columnspan=2,sticky='ew',padx=(0,10))
        
        ### buttons
        Button(lf, text='Reset Values', width=15,
               command=self.reset_values).grid(row=3,column=0,columnspan=2,sticky='ew',padx=10,pady=(2,10))
        Button(lf, text='Submit', width=15,
               command=self.add_customer).grid(row=3,column=3,sticky='ew',padx=(0,10),pady=(2,10))

        for i in range(4):
            lf.columnconfigure(i, weight=1)

        # edit customer
        lf = LabelFrame(self, text="Edit Customer")
        lf.grid(padx=5,pady=5,row=1,column=0,sticky='ew')

        Label(lf, text="Name: ").grid(row=0,column=0,sticky='e',pady=10,padx=(10,0))
        self.name_cb = Combobox(lf, textvariable=self.name, width=30, values=self.names)
        self.name_cb.grid(row=0,column=1,sticky='ew',pady=10)
        Button(lf, text="Edit",width=15,command=self.edit).grid(row=0,column=2,sticky='ew',padx=10,pady=10)

        for i in range(3):
            lf.columnconfigure(i,weight=1)
        self.columnconfigure(0,weight=1)

        self.fname_en.focus_set() #cursor goes here when frame is created
        self.update_names()
        self.reset_values() #zero out all values in new customer

    def edit(self):
        old_name = str(self.name.get())
        parsed = old_name.split(' ',2)
        (line,row) = self.customers.find(parsed[2],parsed[0],parsed[1])
        
        self.ncd.show(line)
        self.refresh() #refresh the global refresh
        name = ' '.join([self.ncd.fname.get(),self.ncd.mname.get(),self.ncd.lname.get()])
        self.output_text("+ - Modified: " + old_name + ' (' + line[3] + ') -> ' + name + " (" + self.ncd.payment.get() + ")\n")

    def update_names(self):
        '''
        update names in edit Combobox
        '''
        self.populate_names()
        if len(self.names) == 0: self.names = ['']
        self.name_cb['values'] = self.names
        self.name_cb.current(0)

    def populate_names(self):
        try:
            clist = self.customers.get_list()
        except IOError:
            self.output_text("! - " + self.customers.filename + " open in another application.\n")
            return
        clist.sort(key = lambda x: ', '.join(x[0:3]).lower())
        self.names = []
        for line in clist:
            self.names.append(' '.join([line[1],line[2],line[0]]))

    def reset_values(self):
        self.fname.set('')
        self.mname.set('')
        self.lname.set('')
#.........这里部分代码省略.........
开发者ID:tylerjw,项目名称:jim_tracker,代码行数:103,代码来源:customer.py

示例4: __init__

# 需要导入模块: from ttk import Entry [as 别名]
# 或者: from ttk.Entry import focus_set [as 别名]
	def __init__(self, root):
		register_openers()
		Tkinter.Frame.__init__(self, root)
		self.root = root
		self.root.title("GoData Client Module")
		self.grid()
		Style().configure("TButton", padding=(0, 5, 0, 5), 
          	font='serif 10')
        
       		self.root.columnconfigure(0, pad=3)
        	self.root.columnconfigure(1, pad=3)
        	self.root.columnconfigure(2, pad=3)
        	self.root.columnconfigure(3, pad=3)
		self.root.columnconfigure(4, pad=3)
        
       		self.root.rowconfigure(0, pad=3)
        	self.root.rowconfigure(1, pad=3)
        	self.root.rowconfigure(2, pad=3)
        	self.root.rowconfigure(3, pad=3)
        	self.root.rowconfigure(4, pad=3)
		self.root.rowconfigure(5, pad=3)
		self.root.rowconfigure(6, pad=3)
		self.root.rowconfigure(7, pad=3)
		self.root.rowconfigure(8, pad=3)
		self.root.rowconfigure(9, pad=3)
		self.root.rowconfigure(10, pad=3)
		self.root.rowconfigure(11, pad=3)
		self.root.rowconfigure(12, pad=3)
		self.root.rowconfigure(13, pad=3)
		self.root.rowconfigure(14, pad=3)
		self.root.rowconfigure(15, pad=3)
		self.root.rowconfigure(16, pad=3)
		self.root.rowconfigure(17, pad=3)
		self.root.rowconfigure(18, pad=3)
		self.root.rowconfigure(19, pad=3)
		self.root.rowconfigure(20, pad=3)
		self.root.rowconfigure(21, pad=3)
		self.root.rowconfigure(22, pad=3)

		self.root.rowconfigure(0, weight=1)
        	self.root.columnconfigure(0, weight=1)
		global e
		e = Entry(self, width=4)
		e.grid(row=16, column=4)
		e.focus_set()
		
		#self.button = Button(self, text="Upload", fg="red", command=self.logout)
		#self.button.pack(side = RIGHT)
		
		
  		button_opt = {'fill': Tkconstants.BOTH, 'padx': 5, 'pady': 5}
		a = Tkinter.Button(self, text='Browse', command=self.askopenfilename)#.pack(**button_opt)
		a.grid(row =1 , column =4)		
		b = Tkinter.Button(self, text='Upload', command=self.upload)#.pack(**button_opt)
		b.grid(row = 3, column =4)		
		
		f=client.doCmd({"cmd":"view"})
		for i in f:
			FileInfo[i.split(":")[0]].append(i.split(":")[1].split("/")[-1])		
		
		print FileInfo
       		t = SimpleTable(self, len(f)/5,5)
		t.grid(row = 4, column =4)
		
		#MyButton1 = Button(self, text="Download 5", width=14, command=self.Download)
		#MyButton1.grid(row=15, column=4)

		#MyButton2 = Button(self, text="Download 6", width=14, command=self.Download)
		#MyButton2.grid(row=15, column=5)

		#MyButton3 = Button(self, text="Download 7", width=14, command=self.Download)
		#MyButton3.grid(row=15, column=6)	
	
		#MyButton4 = Button(self, text="Download 4", width=14, command=self.Download)
		#MyButton4.grid(row=15, column=3)

		#MyButton5 = Button(self, text="Download 3", width=14, command=self.Download)
		#MyButton5.grid(row=15, column=2)

		#MyButton6 = Button(self, text="Download 2", width=14, command=self.Download)
		#MyButton6.grid(row=15, column=1)

		#MyButton7 = Button(self, text="Download 1", width=14, command=self.Download)
		#MyButton7.grid(row=15, column=0)

		#MyButton8 = Button(self, text="Download 8", width=14, command=self.Download)
		#MyButton8.grid(row=15, column=7)

		MyButton9 = Button(self, text="Download", width=14, command=self.callback)
		MyButton9.grid(row=17, column=4)

		creation = tk.Label( self, text = "Created by Kuber, Digvijay, Anahita & Payal", borderwidth =5, width =45)
		creation.grid(row=50 , column = 4)
		

	
		self.file_opt = options = {}		
  		options['defaultextension'] = '.txt'
  		options['filetypes'] = [('all files', '.*'), ('text files', '.txt')]
  	        options['initialdir'] = 'C:\\'
#.........这里部分代码省略.........
开发者ID:kuberkaul,项目名称:Go-Data,代码行数:103,代码来源:gui(tkinter).py

示例5: AdderApp

# 需要导入模块: from ttk import Entry [as 别名]
# 或者: from ttk.Entry import focus_set [as 别名]
class AdderApp(Frame):
    def __init__(self):
        Frame.__init__(self)
        self.master.title("Adder App")
        #self.master.geometry("200x150")

        self.instructions = Label(self, text="Enter the value to add to:")
        self.instructions.pack(pady=5)

        self.number = Entry(self)
        self.number.focus_set()
        self.number.pack(pady=5)

        self.total = Tkinter.StringVar()
        self.time = Tkinter.StringVar()

        self.total_frame = Frame(self)
        self.total_frame.pack(pady=0)
        Label(self.total_frame, text="Total:").pack(side=Tkinter.LEFT, padx=5)
        Label(self.total_frame, textvariable=self.total).pack(side=Tkinter.LEFT)
        self.time_frame = Frame(self)
        self.time_frame.pack(pady=0)
        Label(self.time_frame, text="Time:").pack(side=Tkinter.LEFT)
        Label(self.time_frame, textvariable=self.time).pack(side=Tkinter.LEFT)
        self.complete_msg = Tkinter.StringVar()
        Label(self, textvariable=self.complete_msg).pack(pady=2)

        self.buttons = Frame(self)
        self.buttons.pack(side=Tkinter.BOTTOM, pady=2)
        self.quit_btn = Button(self.buttons, text="Quit", command=self.quit)
        self.quit_btn.pack(side=Tkinter.LEFT)
        self.quit_btn.bind("<Return>", (lambda e, b=self.quit_btn: b.invoke()))
        self.run_btn = Button(self.buttons, text="Run", command=self.run, default=Tkinter.ACTIVE)
        self.run_btn.pack(side=Tkinter.LEFT)

        self.pack(fill=Tkinter.X)
        self.master.bind("<Return>", (lambda e, b=self.run_btn: b.invoke()))

    def run_btn_invoke(self, e):
        print("starting run with button enter")
        self.run_btn.invoke()

    def run(self):
        self.complete_msg.set("")

        self.add_run = adder.Adder()
        self.t = threading.Thread(target=self.add_run.run_to, args=(int(self.number.get()),))
        self.t.start()

        self.update_status()

    def update_status(self):
        self.total.set(self.add_run.total)
        try:
            self.time.set(self.add_run.elapsed_seconds())
        except Exception:
            pass

        if self.add_run.complete:
            self.add_run.complete = False
            self.complete_msg.set("Run Complete")
            self.quit_btn.focus_set()

        self.after(50, self.update_status)
开发者ID:teeks99,项目名称:career-day,代码行数:66,代码来源:app.py

示例6: fileExplorer

# 需要导入模块: from ttk import Entry [as 别名]
# 或者: from ttk.Entry import focus_set [as 别名]
class fileExplorer(Frame):
  
    def __init__(self, parent):
        Frame.__init__(self, parent)   
         
        self.parent = parent
        #Determines which checkbox is active.
        self.option = 0
        
        #Setup window.
        self.parent.title("REA5PE")
        self.style = Style()
        self.style.theme_use("default")
        self.pack(fill=BOTH, expand=1)
		
        #Create label
        lbl = Label(self, text="Select the format PE file.")
        lbl.grid(sticky=W)
		
        #Create checkbox 1
        self.var = IntVar()
        cb = Checkbutton(self, text="Show .txt",
        variable=self.var, command=self.onClick)
        cb.grid(row=1, column=0, sticky=W)
        
        #Create checkbox 2
        self.var2 = IntVar()
        cb2 = Checkbutton(self, text="Show Console",
        variable=self.var2, command=self.onClick2)
        cb2.grid(row=2, column=0, sticky=W)
        
        #Entry form
        self.e1 = Entry(self)
        self.e1.grid(row=3, column=0)
        self.e1.focus_set() #Currently owns focus
   
        #Submission
        abtn = Button(self, text="Disassemble", command=self.onClickDisassemble)
        abtn.grid(row=4, column=0, sticky=W+E)
        
        
     #checkbox1
    def onClick(self):
       
        if self.var.get() == 1:
            self.option+=1 
        else:
            self.option-=1
            
	#checkbox2		
    def onClick2(self):
       
        if self.var2.get() == 1:
            self.option+=2
        else:
            self.option-=2
                
   
    #Disassemble button
    def onClickDisassemble(self):
        #Grab the string from the entry field.
        print "Attempting to launch file: " + self.e1.get()
        decoded = self.e1.get()
        
        if(os.path.isfile(self.e1.get())==True):
            #Launch the process.
            process = Popen(["xed.exe", "-i", decoded], stdout=PIPE)
            (output, err) = process.communicate()
            exit_code = process.wait()
        else:
            print "File does not exist. Terminating application."
            sys.exit()
        
        #Save to file.
        print "Saving to file...."
        fx = open('xeddumptext.txt', 'w')
        fx.write(output)
        fx.close()
        fb = open('xeddumpbinary.txt', 'wb')
        fb.write(output)
        fb.close()
        print "done"
        
        if(self.option==0):
            print "No selection. Please choose a section."
        elif(self.option==1):
            print "Displaying text section only."
            self.extractText();
        elif(self.option==2):
            print "Displaying Console section only."
            self.extractConsole();
        elif(self.option==3):
            print "Displaying both sections."
            self.extractText();
            self.extractConsole();
        else:
            print "Unknown error."
            
    def extractText(self):
        # create child window
#.........这里部分代码省略.........
开发者ID:synexus,项目名称:Python-RE-XED,代码行数:103,代码来源:REfile.py


注:本文中的ttk.Entry.focus_set方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。