Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_quickrun_fix.py
- from Tkinter import *
- import os
- cls=lambda: os.system('cls')
- ttt='''# enter_filename_here.py
- # -- patchwork --
- from Tkinter import *
- import Tkinter as tk
- from PIL import Image
- from PIL import ImageTk
- import tkFileDialog
- import tkMessageBox
- import tkFont
- import Tkconstants
- from tkFileDialog import askopenfilename
- from tkFileDialog import asksaveasfilename
- try:
- import urllib.request as url
- except ImportError:
- import urllib as url
- temp_root=Tk()
- t=tkFont.families()
- tk_fonts=[]
- for font in t:
- if not '@' in font:
- tk_fonts.append(font)
- # print(font)
- temp_root.withdraw()
- # -- end --
- '''
- zzz='''
- tkinter Tkinter
- messagebox. tkMessageBox.
- filedialog. tkFileDialog.
- ttk.
- .ttk
- '''[:-1].splitlines()
- z2='''
- messagebox
- filedialog
- Image
- ImageTk
- '''[:-1].splitlines()
- eval=ttt
- root=Tk('200X200+1+1')
- valid=''
- for z in range(33,127):
- valid += chr(z)
- valid=valid + ' ' + ' '
- print valid
- import tkFont
- t=tkFont.families()
- tk_fonts=[]
- for font in t:
- if not '@' in font:
- tk_fonts.append(font)
- # print(font)
- def clipb():
- def repl(z):
- while '\t\t' in z: z=z.replace('\t\t','\t')
- try:
- a,b=z.split('\t')
- except:
- return t
- return t.replace(a,b)
- def encl(z):
- d=[]
- parentheses={')':'(','}':'{',']':'[','"':'"',"'":"'"}
- s2=sss[sss.index(z):]
- for n,s in enumerate(s2):
- if s == ',' and d == []:
- return s2[:s2.index(s)+1]
- elif s in '[({':
- d.append(s)
- elif s in '])}':
- try:
- d.remove(parentheses[s])
- except:
- return s2[:n]
- t,t2=max([([sss.rindex(z),z] if z in sss else [0,'']) for z in '])}'])
- if t2:
- return sss[:t+1]
- return ''
- try:
- t=root.clipboard_get()
- except:
- cls()
- print '*** Invalid ***'
- return
- if t.strip():
- for z in zzz:
- t=repl(z)
- d=[]
- t=t.replace(' ',' ') # note: does not work in console but from clipboard
- for sss in t.splitlines():
- if 'import' in sss:
- for z in z2:
- if ' '+z in t:
- sss=''
- elif 'font' in sss:
- s2=encl('font')
- font='normal'
- for z in tk_fonts:
- if z in s2:
- font=z
- if sss:
- s=''
- for z in sss:
- if z in valid:
- s += z
- else:
- s += '/'
- if all([(z in s) for z in ('//','#')]):
- s=s.split('#')[0]
- d.append(s.rstrip())
- t=[ttt]+d
- cls()
- for i in t:
- try:
- print i
- except:
- print '???'
- t='\n'.join(t)
- root.clipboard_clear()
- root.clipboard_append(t)
- Frame=LabelFrame(root,height=50,width=250,borderwidth=0,bg="light blue") # note: width=200 minimal
- Frame.pack(fill=X)
- Frame.pack_propagate(False)
- Label(Frame,text="Show Copy Revised In Cleared Console",bg="light blue").pack()
- cpb=Button(Frame,text="Copy From Clipboard",command=clipb)
- cpb.pack()
- root.mainloop()
- '''
- root=Tk("%dx%d+1+1"%(h,w))
- root.minsize(w,h)
- """ >>>
- root=Tk()
- root.geometry("%dx%d+1+1"%(h,w))
- """
- canvas=Canvas(root ,bg="yellow", height="200", width=200)
- arc=canvas.create_arc((5,10,150,200), start=0, extent=150, fill="purple")
- canvas.pack()
- """
- Button The Button is used to add various kinds of buttons to the python application.
- Canvas The canvas widget is used to draw the canvas on the window.
- Checkbutton The Checkbutton is used to display the CheckButton on the window.
- Entry The entry widget is used to display the single-line text field to the user. It is commonly used to accept user values.
- Frame It can be defined as a container to which, another widget can be added and organized.
- Label A label is a text used to display some message or information about the other widgets.
- ListBox The ListBox widget is used to display a list of options to the user.
- Menubutton The Menubutton is used to display the menu items to the user.
- Menu It is used to add menu items to the user.
- Message The Message widget is used to display the message-box to the user.
- Radiobutton The Radiobutton is different from a checkbutton. Here, the user is provided with various options and the user can select only one option among them.
- Scale It is used to provide the slider to the user.
- Scrollbar It provides the scrollbar to the user so that the user can scroll the window up and down.
- Text It is different from Entry because it provides a multi-line text field to the user so that the user can write the text and edit the text inside it.
- Toplevel It is used to create a separate window container.
- Spinbox It is an entry widget used to select from options of values.
- PanedWindow It is like a container widget that contains horizontal or vertical panes.
- LabelFrame A LabelFrame is a container widget that acts as the container
- MessageBox This module is used to display the message-box in the desktop based applications.
- ###
- The pack() method
- The grid() method
- The place() method
- ###
- Grid:
- Column: The column number in which the widget is to be placed. The leftmost column is represented by
- Columnspan: The width of the widget. It represents the number of columns up to which, the column is expanded.
- ipadx, ipady: It represents the number of pixels to pad the widget inside the widget's border.
- padx, pady: It represents the number of pixels to pad the widget outside the widget's border.
- row: The row number in which the widget is to be placed. The topmost row is represented by
- rowspan: The height of the widget, i.e. the number of the row up to which the widget is expanded.
- Sticky: If the cell is larger than a widget, then sticky is used to specify the position of the widget inside the cell. It may be the concatenation of the sticky letters representing the position of the widget. It may be N, E, W, S, NE, NW, NS, EW, ES.
- ###
- Pack:
- expand: If the expand is set to true, the widget expands to fill any space.
- Fill: By default, the fill is set to NONE. However, we can set it to X or Y to determine whether the widget contains any extra space.
- size: it represents the side of the parent to which the widget is to be placed on the window.
- ###
- Place:
- Anchor: It represents the exact position of the widget within the container. The default value (direction) is NW (the upper left corner)
- bordermode: The default value of the border type is INSIDE that refers to ignore the parent's inside the border. The other option is OUTSIDE.
- height, width: It refers to the height and width in pixels.
- relheight, relwidth: It is represented as the float between and indicating the fraction of the parent's height and width.
- relx, rely: It is represented as the float between and that is the offset in the horizontal and vertical direction.
- x, y: It refers to the horizontal and vertical offset in the pixels.
- """
- tkMessageBox.askokcancel("Title","The application will be closed")
- tkMessageBox.askyesno("Title","Do you want to save?")
- tkMessageBox.askretrycancel("Title","Installation failed, try again?")
- tkMessageBox.showinfo("Info","Information...")
- tkMessageBox.showwarning("Warning","Warning...")
- tkMessageBox.showerror("Error","Error...")
- tkMessageBox.askquestion("Confirm","Exit?")
- def button_callback():
- print "click!"
- b=Button(root, text="OK", command=button_callback)
- """ >>>
- -- OR --
- b=Button(root, image=photo, command=button_callback, height= width=
- """
- b.pack()
- """ >>>
- -- OR --
- b.grid()
- -- OR --
- b.place()
- """
- """
- activebackground It represents the background of the button when the mouse hover the button.
- activeforeground It represents the font color of the button when the mouse hover the button.
- Bd It represents the border width in pixels.
- Bg It represents the background color of the button.
- Command It is set to the function call which is scheduled when the function is called.
- Fg Foreground color of the button.
- Font The font of the button text.
- Height The height of the button. The height is represented in the number of text lines for the textual lines or the number of pixels for the images.
- Highlightcolor The color of the highlight when the button has the focus.
- Image It is set to the image displayed on the button.
- justify It illustrates the way by which the multiple text lines are represented. It is set to LEFT for left justification, RIGHT for the right justification, and CENTER for the center.
- Padx Additional padding to the button in the horizontal direction.
- pady Additional padding to the button in the vertical direction.
- Relief It represents the type of the border. It can be SUNKEN, RAISED, GROOVE, and RIDGE.
- State This option is set to DISABLED to make the button unresponsive. The ACTIVE represents the active state of the button.
- Underline Set this option to make the button text underlined.
- Width The width of the button. It exists as a number of letters for textual buttons or pixels for image buttons.
- Wraplength If the value is set to a positive number, the text lines will be wrapped to fit within this length.
- """
- var=StringVar()
- textbox=Entry(root, textvariable=var)
- textbox.focus_set()
- textbox.pack(pady= padx=
- """
- bg The background color of the widget.
- bd The border width of the widget in pixels.
- cursor The mouse pointer will be changed to the cursor type set to the arrow, dot, etc.
- exportselection The text written inside the entry box will be automatically copied to the clipboard by default. We can set the exportselection to to not copy this.
- fg It represents the color of the text.
- font It represents the font type of the text.
- highlightbackground It represents the color to display in the traversal highlight region when the widget does not have the input focus.
- highlightcolor It represents the color to use for the traversal highlight rectangle that is drawn around the widget when it has the input focus.
- highlightthickness It represents a non-negative value indicating the width of the highlight rectangle to draw around the outside of the widget when it has the input focus.
- insertbackground It represents the color to use as background in the area covered by the insertion cursor. This color will normally override either the normal background for the widget.
- insertborderwidth It represents a non-negative value indicating the width of the D border to draw around the insertion cursor. The value may have any of the forms acceptable to Tk_GetPixels.
- insertofftime It represents a non-negative integer value indicating the number of milliseconds the insertion cursor should remain "off" in each blink cycle. If this option is zero, then the cursor doesn't blink: it is on all the time.
- insertontime Specifies a non-negative integer value indicating the number of milliseconds the insertion cursor should remain "on" in each blink cycle.
- insertwidth It represents the value indicating the total width of the insertion cursor. The value may have any of the forms acceptable to Tk_GetPixels.
- justify It specifies how the text is organized if the text contains multiple lines.
- relief It specifies the type of the border. Its default value is FLAT.
- selectbackground The background color of the selected text.
- selectborderwidth The width of the border to display around the selected task.
- selectforeground The font color of the selected task.
- show It is used to show the entry text of some other type instead of the string. For example, the password is typed using stars (*).
- textvariable It is set to the instance of the StringVar to retrieve the text from the entry.
- width The width of the displayed text or image.
- xscrollcommand The entry widget can be linked to the horizontal scrollbar if we want the user to enter more text then the actual width of the widget.
- ###
- delete(first, last=none) It is used to delete the specified characters inside the widget.
- get() It is used to get the text written inside the widget.
- icursor(index) It is used to change the insertion cursor position. We can specify the index of the character before which, the cursor to be placed.
- index(index) It is used to place the cursor to the left of the character written at the specified index.
- insert(index,s) It is used to insert the specified string before the character placed at the specified index.
- select_adjust(index) It includes the selection of the character present at the specified index.
- select_clear() It clears the selection if some selection has been done.
- select_form(index) It sets the anchor index position to the character specified by the index.
- select_present() It returns true if some text in the Entry is selected otherwise returns false.
- select_range(start,end) It selects the characters to exist between the specified range.
- select_to(index) It selects all the characters from the beginning to the specified index.
- xview(index) It is used to link the entry widget to a horizontal scrollbar.
- xview_scroll(number,what) It is used to make the entry scrollable horizontally.
- """
- checkvarIntVar()
- checkvarIntVar()
- checkvarIntVar()
- chkbtnCheckbutton(root, text="A", variable=checkvar onvalue= offvalue= height= width=
- chkbtnCheckbutton(root, text="B", variable=checkvar onvalue= offvalue= height= width=
- chkbtnCheckbutton(root, text="C", variable=checkvar onvalue= offvalue= height= width=
- chkbtnpack()
- chkbtnpack()
- chkbtnpack()
- """
- activebackground It represents the background color when the checkbutton is under the cursor.
- activeforeground It represents the foreground color of the checkbutton when the checkbutton is under the cursor.
- bg The background color of the button.
- bitmap It displays an image (monochrome) on the button.
- bd The size of the border around the corner.
- command It is associated with a function to be called when the state of the checkbutton is changed.
- cursor The mouse pointer will be changed to the cursor name when it is over the checkbutton.
- disableforeground It is the color which is used to represent the text of a disabled checkbutton.
- font It represents the font of the checkbutton.
- fg The foreground color (text color) of the checkbutton.
- height It represents the height of the checkbutton (number of lines). The default height is highlightcolor The color of the focus highlight when the checkbutton is under focus.
- image The image used to represent the checkbutton.
- justify This specifies the justification of the text if the text contains multiple lines.
- offvalue The associated control variable is set to by default if the button is unchecked. We can change the state of an unchecked variable to some other one.
- onvalue The associated control variable is set to by default if the button is checked. We can change the state of the checked variable to some other one.
- padx The horizontal padding of the checkbutton
- pady The vertical padding of the checkbutton.
- relief The type of the border of the checkbutton. By default, it is set to FLAT.
- selectcolor The color of the checkbutton when it is set. By default, it is red.
- selectimage The image is shown on the checkbutton when it is set.
- state It represents the state of the checkbutton. By default, it is set to normal. We can change it to DISABLED to make the checkbutton unresponsive. The state of the checkbutton is ACTIVE when it is under focus.
- underline It represents the index of the character in the text which is to be underlined. The indexing starts with zero in the text.
- variable It represents the associated variable that tracks the state of the checkbutton.
- width It represents the width of the checkbutton. It is represented in the number of characters that are represented in the form of texts.
- wraplength If this option is set to an integer number, the text will be broken into the number of pieces.
- ###
- deselect() It is called to turn off the checkbutton.
- flash() The checkbutton is flashed between the active and normal colors.
- invoke() This will invoke the method associated with the checkbutton.
- select() It is called to turn on the checkbutton.
- toggle() It is used to toggle between the different Checkbuttons.
- """
- img=PhotoImage(file="pylogo.png")
- panel=Label(root, image=img)
- panel.pack(side="bottom", fill="both", expand="yes")
- root.title('Hello')
- a=Label(root, text='Hello World!')
- a.pack(pady=padx=
- def donothing():
- pass
- frame=Frame(root)
- frame.pack()
- leftframe=Frame(root)
- leftframe.pack(side=LEFT)
- rightframe=Frame(root)
- rightframe.pack(side=RIGHT)
- """
- bd It represents the border width.
- bg The background color of the widget.
- cursor The mouse pointer is changed to the cursor type set to different values like an arrow, dot, etc.
- height The height of the frame.
- highlightbackground The color of the background color when it is under focus.
- highlightcolor The text color when the widget is under focus.
- highlightthickness It specifies the thickness around the border when the widget is under the focus.
- relief It specifies the type of the border. The default value if FLAT.
- width It represents the width of the widget.
- """
- btnButton(frame, text="Submit", fg="red",activebackground="red")
- btnpack(side=LEFT)
- btnButton(frame, text="Remove", fg="brown", activebackground="brown")
- btnpack(side=RIGHT)
- btnButton(rightframe, text="Add", fg="blue", activebackground="blue")
- btnpack(side=LEFT)
- btnButton(leftframe, text="Modify", fg="black", activebackground="white")
- btnpack(side=RIGHT)
- listbox=Listbox(root)
- listbox.insert( "Item A")
- listbox.insert( "Item B")
- listbox.insert( "Item C")
- listbox.insert( "Item D")
- btn=Button(root, text="delete", command=lambda listbox=listbox: listbox.delete(ANCHOR))
- listbox.pack()
- btn.pack()
- """
- activate(index) It is used to select the lines at the specified index.
- curselection() It returns a tuple containing the line numbers of the selected element or elements, counting from If nothing is selected, returns an empty tuple.
- delete(first, last=None) It is used to delete the lines which exist in the given range.
- get(first, last=None) It is used to get the list items that exist in the given range.
- index(i) It is used to place the line with the specified index at the top of the widget.
- insert(index, *elements) It is used to insert the new lines with the specified number of elements before the specified index.
- nearest(y) It returns the index of the nearest line to the y coordinate of the Listbox widget.
- see(index) It is used to adjust the position of the listbox to make the lines specified by the index visible.
- size() It returns the number of lines that are present in the Listbox widget.
- xview() This is used to make the widget horizontally scrollable.
- xview_moveto(fraction) It is used to make the listbox horizontally scrollable by the fraction of width of the longest line present in the listbox.
- xview_scroll(number, what) It is used to make the listbox horizontally scrollable by the number of characters specified.
- yview() It allows the Listbox to be vertically scrollable.
- yview_moveto(fraction) It is used to make the listbox vertically scrollable by the fraction of width of the longest line present in the listbox.
- yview_scroll(number, what) It is used to make the listbox vertically scrollable by the number of characters specified.
- """
- spin = Spinbox(root, from_= 0, to = 25)
- spin.pack()
- """
- """
- menubar=Menu(root)
- filemenu=Menu(menubar, tearoff=
- filemenu.add_command(label="New", command=donothing)
- filemenu.add_command(label="Open", command=donothing)
- filemenu.add_command(label="Save", command=donothing)
- filemenu.add_separator()
- filemenu.add_command(label="Exit", command=root.quit)
- menubar.add_cascade(label="File", menu=filemenu)
- helpmenu=Menu(menubar, tearoff=
- helpmenu.add_command(label="Help Index", command=donothing)
- helpmenu.add_command(label="About...", command=donothing)
- menubar.add_cascade(label="Help", menu=helpmenu)
- root.config(menu=menubar)
- img_types=(("png files","*.png"),("jpeg files","*.jpg"),("all files","*.*"))
- filename=tkFileDialog.askopenfilename(initialdir="/",title="Select file",filetypes=img_types)
- tkFileDialog.asksaveasfilename(initialdir="/",title="Select file",filetypes=img_types)
- menubutton=Menubutton(root, text="File Type", relief=FLAT)
- menubutton.grid()
- menubutton.menu=Menu(menubutton)
- menubutton["menu"]=menubutton.menu
- menubutton.menu.add_checkbutton(label="Hindi", variable=IntVar())
- menubutton.menu.add_checkbutton(label="English", variable=IntVar())
- menubutton.pack()
- root.mainloop()
- """
- activebackground The background color of the widget when the widget is under focus.
- activeforeground The font color of the widget text when the widget is under focus.
- anchor It specifies the exact position of the widget content when the widget is assigned more space than needed.
- bg It specifies the background color of the widget.
- bitmap It is set to the graphical content which is to be displayed to the widget.
- bd It represents the size of the border. The default value is pixels.
- cursor The mouse pointer will be changed to the cursor type specified when the widget is under the focus. The possible value of the cursor type is arrow, or dot etc.
- direction It direction can be specified so that menu can be displayed to the specified direction of the button. Use LEFT, RIGHT, or ABOVE to place the widget accordingly.
- disabledforeground The text color of the widget when the widget is disabled.
- fg The normal foreground color of the widget.
- height The vertical dimension of the Menubutton. It is specified as the number of lines.
- highlightcolor The highlight color shown to the widget under focus.
- image The image displayed on the widget.
- justify This specified the exact position of the text under the widget when the text is unable to fill the width of the widget. We can use the LEFT for the left justification, RIGHT for the right justification, CENTER for the centre justification.
- menu It represents the menu specified with the Menubutton.
- padx The horizontal padding of the widget.
- pady The vertical padding of the widget.
- relief This option specifies the type of the border. The default value is RAISED.
- state The normal state of the Mousebutton is enabled. We can set it to DISABLED to make it unresponsive.
- text The text shown with the widget.
- textvariable We can set the control variable of string type to the text variable so that we can control the text of the widget at runtime.
- underline The text of the widget is not underlined by default but we can set this option to make the text of the widget underlined.
- width It represents the width of the widget in characters. The default value is wraplength We can break the text of the widget in the number of lines so that the text contains the number of lines not greater than the specified value.
- """
- sb=Scrollbar(root)
- sb.pack(side=RIGHT, fill=Y)
- mylist=Listbox(root, yscrollcommand=sb.set)
- for line in range(:
- mylist.insert(END, "Number " + str(line))
- mylist.pack(side=LEFT)
- sb.config(command=mylist.yview)
- """
- activebackground The background color of the widget when it has the focus.
- bg The background color of the widget.
- bd The border width of the widget.
- command It can be set to the procedure associated with the list which can be called each time when the scrollbar is moved.
- cursor The mouse pointer is changed to the cursor type set to this option which can be an arrow, dot, etc.
- elementborderwidth It represents the border width around the arrow heads and slider. The default value is -
- Highlightbackground The focus highlighcolor when the widget doesn't have the focus.
- highlighcolor The focus highlighcolor when the widget has the focus.
- highlightthickness It represents the thickness of the focus highlight.
- jump It is used to control the behavior of the scroll jump. If it set to then the callback is called when the user releases the mouse button.
- orient It can be set to HORIZONTAL or VERTICAL depending upon the orientation of the scrollbar.
- repeatdelay This option tells the duration up to which the button is to be pressed before the slider starts moving in that direction repeatedly. The default is ms.
- repeatinterval The default value of the repeat interval is
- takefocus We can tab the focus through this widget by default. We can set this option to if we don't want this behavior.
- troughcolor It represents the color of the trough.
- width It represents the width of the scrollbar.
- ###
- get() It returns the two numbers a and b which represents the current position of the scrollbar.
- set(first, last) It is used to connect the scrollbar to the other widget w. The yscrollcommand or xscrollcommand of the other widget to this method.
- """
- def selection():
- selection = "You selected the option " + str(radio.get())
- label.config(text = selection)
- top = Tk()
- top.geometry("300x150")
- radio = IntVar()
- lbl = Label(text = "Favourite programming language:")
- lbl.pack()
- R1 = Radiobutton(top, text="A", variable=radio, value=1,
- command=selection)
- R1.pack( anchor = W )
- R2 = Radiobutton(top, text="B", variable=radio, value=2,
- command=selection)
- R2.pack( anchor = W )
- R3 = Radiobutton(top, text="C", variable=radio, value=3,
- command=selection)
- R3.pack( anchor = W)
- label = Label(top)
- label.pack()
- """
- activebackground The background color of the widget when it has the focus.
- activeforeground The font color of the widget text when it has the focus.
- anchor It represents the exact position of the text within the widget if the widget contains more space than the requirement of the text. The default value is CENTER.
- bg The background color of the widget.
- bitmap It is used to display the graphics on the widget. It can be set to any graphical or image object.
- borderwidth It represents the size of the border.
- command This option is set to the procedure which must be called every-time when the state of the radiobutton is changed.
- cursor The mouse pointer is changed to the specified cursor type. It can be set to the arrow, dot, etc.
- font It represents the font type of the widget text.
- fg The normal foreground color of the widget text.
- height The vertical dimension of the widget. It is specified as the number of lines (not pixel).
- highlightcolor It represents the color of the focus highlight when the widget has the focus.
- highlightbackground The color of the focus highlight when the widget is not having the focus.
- image It can be set to an image object if we want to display an image on the radiobutton instead the text.
- justify It represents the justification of the multi-line text. It can be set to CENTER(default), LEFT, or RIGHT.
- padx The horizontal padding of the widget.
- pady The vertical padding of the widget.
- relief The type of the border. The default value is FLAT.
- selectcolor The color of the radio button when it is selected.
- selectimage The image to be displayed on the radiobutton when it is selected.
- state It represents the state of the radio button. The default state of the Radiobutton is NORMAL. However, we can set this to DISABLED to make the radiobutton unresponsive.
- text The text to be displayed on the radiobutton.
- textvariable It is of String type that represents the text displayed by the widget.
- underline The default value of this option is - however, we can set this option to the number of character which is to be underlined.
- value The value of each radiobutton is assigned to the control variable when it is turned on by the user.
- variable It is the control variable which is used to keep track of the user's choices. It is shared among all the radiobuttons.
- width The horizontal dimension of the widget. It is represented as the number of characters.
- wraplength We can wrap the text to the number of lines by setting this option to the desired number so that each line contains only that number of characters.
- ###
- deselect() It is used to turn of the radiobutton.
- flash() It is used to flash the radiobutton between its active and normal colors few times.
- invoke() It is used to call any procedure associated when the state of a Radiobutton is changed.
- select() It is used to select the radiobutton. )
- """
- '''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement