This example demonstrates the use of the Python Tkinter base control and is shared for your reference. The specific method is as follows:
#-*-Coding:utf-8-*-from tkinter import * def btn_click (): b2[' text '] = ' clicked ' Evalue = E.get () print ' btn Click and Entry value is%s '% Evalue def btn_click_bind (event): print ' Enter B2 ' Def show_toplevel (): top = Toplev El () Top.title (' 2nd window '
Python script has been written for a while, the advantages of the Python language does not have to say, but the GUI programming seems very few, looking for to find is the following two most reliable, but are the basis, really if the actual writing, but also to see the various code to do.
"Tkinter+programming+code+by+examples.pdf" http://vdisk.weibo.com/s/pNW4u
"Tkinter.pdf" Http://vdisk.weibo.com/s/pJ0Al
TopLevel's use has an article written particul
The TopLevel (top-level window) component is similar to a frame component, but the TopLevel component is a stand-alone top-level window that usually has parts such as title bars, borders, and so on, and is the same as the root window created by TK (), sharing the same method.
When to use the TopLevel component.
TopLevel components are typically used to display additional windows, dialogs, or other pop-up windows.
In the following example, we add a button to the root window to create a top-leve
When testing photoimage individually
From Tkinter Import *
From PiL. IMAGETK Import Photoimage
A = Photoimage (file= ' your file path ')
You may encounter the "too early to create image" problem
Google to the solution:
You are forgot to declare root-root = Tk (). The TK system must is on before using it.
You should declare a TK (TopLevel is also possible) before using Photoimage ()
From Tkinter
The @ Overview TK is a (available for multi-platform) GUI library; Tkinter is the interface of the Python language to access the library and the standard for Python's GUI development;
@ First GUI interface
From tkinter Import *
# Create a program window
= Tk ()
# Create a control instance
lable = Label (
window, # parent Container
text= Hello " # optional keyword parameters (see source note)
but
Use this little game to learn how to use the Tkinter in ython3.3
Copy Code code as follows:
#-*-Coding:utf-8-*-
Import Tkinter as TK
Import Sys
Import Random
Import re
Number = Random.randint (0,1024)running = Truenum = 0NMAXN = 1024Nminn = 0
def ebtnclose (event):Root.destroy ()def ebtnguess (event):Global NMAXNGlobal NminnGlobal numGlobal Running#修改缺陷: User is correct, prompt tag also
method, as follows:Items = Your_treeview.get_children () [Your_treeview.delete (item) for item in items]7. How do I get the value of the cell TTK the TreeView is double-clicked?Theoretically, only through the control is no solution. The resolution is defined by the way you define the boundaries of the coordinates, which defines the width (in pixel units) for each column. Event.x/y can take the coordinates. You can analyze the coordinate range of the column in which the coordinate falls.Header_w
Drop ~ Today.
Before touching a bit of tkinter, GUI programming a little interest, so on their own thinking to write a small program (haha, too small can not be small program). Well, after all, it's all about the automated tests, so it's a matter of having an automated test. In last week's blogger's notes, there was a solution to the validation code encountered when writing an automated logon script.
Before we mentioned four solutions, let's review:
)res =hashlib.md5 ()Try: #It'll add a new line characterRes.update (Dec[0:-1].encode ('ASCII')) except: returnFalse Result.insert (1.0, Res.hexdigest ())//Insert the data after MD5 into the output edit controlreturnTrueif __name__=='__main__': Main ()Iv. Simple Self-summary:Before the production of this gadget, encountered some problems and some small tricks, such as the button to pass the parameters of the problem, you can use the expression of lambda easy to complete, and not
Source code from http://www.brunningonline.net/simon/blog/archives/SysTrayIcon.py.html
In fact, this source code can be used directly, but it does not take into account the combination of the tray and other programs, but a separate tray. Most of the cases where pallets are used are GUI programs. I use tkinter. Therefore, some modifications were made:
#-*-Coding: GBK-*-# module: javasrayicon. PY # Synopsis: Windows System Tray Icon. # programmer: Simo
Python Gui-tkinter Fonts: The first element as a tuple is the font family, the size of a point, optionally a string that contains one or more bold, italic, underlined style modifiers, bold.there can be up to three ways to specify a type style.Simple tuple font:As the first element of a tuple is the font family, the size of a point, you can choose a string that contains one or more bold, italic, underlined style modifiers, bold.Example:
("Helv
You want to make a simple Python script editor where the text input Code section is implemented using the text control in Tkinter.But the question is, how do you achieve highlighting? Refer to Python's own editor: code in the Python27/vidle folder.The implementation effect Is:One of the main ideas is that in text every input line of code, all through regular matching, to find whether it is necessary to highlight the effect, the reason is very simple, but the problem is that when using the text c
directory is set to the current directory ifError:self.cwd.set (Error)#set CWD to errorSelf.top.update ()#Refresh PageSleep (2) if not(Hasattr (Self,' Last') andself.last): Self.last=os.curdir Self.cwd.set (self.last)#Reset CWD to the current directorySelf.dirs.config (selectbackground='Lightskyblue') self.top.update ()#Refresh Page returnSelf.cwd.set ('fetching DIRECTORY CONTENTS ...') self.top.update () dirlist= Os.listdir (Tdir)#list all files under file directo
corresponding setting of the value logic for the form is as follows: def set_data (self, data): if isn't isinstance (data,dict): raise TypeError if not self.mapper: raise "set _mapper method must is called before this method being called. " Ctrls = Dict ([(X._NAME,X) for x in Self.get_input_ctrls ()]))- k,v in Self.mapper.items (): if Data.get (k,false) : ctrl_obj = Ctrls.get (v) if ctrl_obj:
All kinds of window bar, quite simple,
Look at the tutorials, the tutorials URL click on the Open link
Tried a variety of window.
Source:
Import tkinter.messagebox
import tkinter as TK
window=tk. Tk ()
window.title (' menu ')
window.geometry (' 400x400 ')
def hit ():
#box系列
# Tk.messagebox.showinfo (title= ' Hi ', message= ' So is a MsgBox ')
#tk. messagebox.showwarning (title= ' warning '), Message= ' So is a Warningbox ')
#tk
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.