SHARE
TWEET

tkinter

dipollwody Apr 24th, 2019 101 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from tkinter import *
  2. import tkinter as tk
  3. import tkinter.font as tkFont
  4. import tkinter.ttk as ttk
  5. import tkinter.scrolledtext as scrolledtext
  6.  
  7.  
  8. SUFFIXES = {1000: ['KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],
  9.             1024: ['KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB']}
  10.  
  11.  
  12.  
  13.    
  14. def approximate_size(size, a_kilobyte_is_1024_bytes=True):
  15.     '''Convert a file size to human-readable form.
  16.  
  17.     Keyword arguments:
  18.     size -- file size in bytes
  19.     a_kilobyte_is_1024_bytes -- if True (default), use multiples of 1024
  20.                                 if False, use multiples of 1000
  21.  
  22.  
  23.  
  24.     Returns: string
  25.  
  26.     '''
  27.     if size < 0:
  28.         raise ValueError('number must be non-negative')
  29.  
  30.     multiple = 1024 if a_kilobyte_is_1024_bytes else 1000
  31.     for suffix in SUFFIXES[multiple]:
  32.         size /= multiple
  33.         if size < multiple:
  34.             return '{0:.1f} {1}'.format(size, suffix)
  35.  
  36.     raise ValueError('number too large')
  37.  
  38. if __name__ == '__main__':
  39.     print(approximate_size(1000000000000, False))
  40.     print(approximate_size(1000000000000))
  41.  
  42.  
  43. LARGE_FONT= ("Verdana", 12)
  44.  
  45.  
  46. class SeaofBTCapp(tk.Tk):
  47.  
  48.     def __init__(self, *args, **kwargs):
  49.        
  50.         tk.Tk.__init__(self, *args, **kwargs)
  51.         container = tk.Frame(self)
  52.  
  53.         container.pack(side="top", fill="both", expand = True)
  54.  
  55.         container.grid_rowconfigure(0, weight=1)
  56.         container.grid_columnconfigure(0, weight=1)
  57.        
  58.  
  59.         self.frames = {}
  60.  
  61.         for F in (StartPage, PageOne, PageTwo, PageTre, PageFour, PageFive, PageSix, PageSeven, PageEight,):
  62.  
  63.             frame = F(container, self)
  64.  
  65.             self.frames[F] = frame
  66.  
  67.             frame.grid(row=0, column=0, sticky="nsew")
  68.  
  69.         self.show_frame(StartPage)
  70.  
  71.     def show_frame(self, cont):
  72.  
  73.         frame = self.frames[cont]
  74.         frame.tkraise()
  75.  
  76.        
  77.        
  78.        
  79. top = Tk()
  80. top.geometry("100x300+1600+120")
  81. mb =  Menubutton ( top, text = "condiments", relief = RAISED )
  82. mb.grid()
  83. mb.menu  =  Menu ( mb, tearoff = 0 )
  84. mb["menu"]  =  mb.menu
  85.    
  86. mayoVar  = IntVar()
  87. ketchVar = IntVar()
  88.  
  89. mb.menu.add_checkbutton ( label = "mayo",
  90.                           variable = mayoVar )
  91. mb.menu.add_checkbutton ( label = "ketchup",
  92.                           variable = ketchVar )
  93.  
  94.  
  95. from tkinter import *
  96. def donothing():
  97.    filewin = Toplevel(root)
  98.    button = Button(filewin, text="Do nothing button")
  99.    button.pack()
  100.    
  101. root = Tk()
  102. root.geometry("200x300+150+20")
  103. menubar = Menu(root)
  104. filemenu = Menu(menubar, tearoff = 0)
  105. filemenu.add_command(label="New", command = donothing)
  106. filemenu.add_command(label = "Open", command = donothing)
  107. filemenu.add_command(label = "Save", command = donothing)
  108. filemenu.add_command(label = "Save as...", command = donothing)
  109. filemenu.add_command(label = "Close", command = donothing)
  110.  
  111. filemenu.add_separator()
  112.  
  113. filemenu.add_command(label = "Exit", command = root.quit)
  114. menubar.add_cascade(label = "File", menu = filemenu)
  115. editmenu = Menu(menubar, tearoff=0)
  116. editmenu.add_command(label = "Undo", command = donothing)
  117.  
  118. editmenu.add_separator()
  119.  
  120. editmenu.add_command(label = "Cut", command = donothing)
  121. editmenu.add_command(label = "Copy", command = donothing)
  122. editmenu.add_command(label = "Paste", command = donothing)
  123. editmenu.add_command(label = "Delete", command = donothing)
  124. editmenu.add_command(label = "Select All", command = donothing)
  125.  
  126. menubar.add_cascade(label = "Edit", menu = editmenu)
  127. helpmenu = Menu(menubar, tearoff=0)
  128. helpmenu.add_command(label = "Help Index", command = donothing)
  129. helpmenu.add_command(label = "About...", command = donothing)
  130. menubar.add_cascade(label = "Help", menu = helpmenu)
  131.  
  132. root.config(menu = menubar)
  133.  
  134.  
  135.  
  136. window = tk.Tk() # tworzenie okna głównego
  137.  
  138. window.title( "Hello World" ) # ustawienie tytułu okna głównego
  139. # tworzenie kontrolki typu label
  140. window.geometry("1000x800+500+20")
  141. label = tk.Label( window, text = "Witaj Świecie programowania\nCo swym urokiemnas zabawia\nCo otwiera nowe możliwości\nZ binarnych liczb złożoności" )
  142.  
  143. label.pack( side = tk.BOTTOM ) # podpinanie kontrolki pod okno
  144.  
  145.  
  146.  
  147.  
  148. class GUI(object):
  149.  
  150.     def __init__(self):
  151.         root = self.root = tkinter.Tk()
  152.         root.title('Test')
  153.  
  154.     # make the top right close button minimize (iconify) the main window
  155.         root.protocol("WM_DELETE_WINDOW", root.iconify)
  156.  
  157.     # make Esc exit the program
  158.         root.bind('<Escape>', lambda e: root.destroy())
  159.  
  160.     # create a menu bar with an Exit command
  161.         menubar = tkinter.Menu(root)
  162.         filemenu = tkinter.Menu(menubar, tearoff=0)
  163.         filemenu.add_command(label="Exit", command=root.destroy)
  164.         menubar.add_cascade(label="File", menu=filemenu)
  165.         root.config(menu=menubar)
  166.  
  167.     # create a Text widget with a Scrollbar attached
  168.         txt = scrolledtext.ScrolledText(root, undo=True)
  169.         txt['font'] = ('consolas', '12')
  170.         txt.pack(expand=True, fill='both')
  171.  
  172. gui = GUI()
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184. class StartPage(tk.Frame):
  185.  
  186.     def __init__(self, parent, controller):
  187.         tk.Frame.__init__(self,parent)
  188.          
  189.         label = tk.Label(self, text="glowna strona", font=LARGE_FONT)
  190.  
  191.         label.pack(pady=10,padx=10)
  192.        
  193.        
  194.  
  195.    
  196.    
  197.    
  198.  
  199.    
  200.    
  201.  
  202.    
  203.    
  204.  
  205.        
  206.        
  207.        
  208.        
  209.        
  210.  
  211.         button = tk.Button(self, text="omnie",
  212.                             command=lambda: controller.show_frame(PageOne))
  213.         button.pack()
  214.  
  215.         button2 = tk.Button(self, text="biblioteka",
  216.                             command=lambda: controller.show_frame(PageTwo))
  217.         button2.pack()
  218.  
  219.         button3 = tk.Button(self, text="cwiczenia",
  220.                             command=lambda: controller.show_frame(PageTre))
  221.         button3.pack()
  222.        
  223.         button4 = tk.Button(self, text="drewno i wegiel",
  224.                             command=lambda: controller.show_frame(PageTre))
  225.         button4.pack()
  226.         button5 = tk.Button(self, text="przeczytane",
  227.                             command=lambda: controller.show_frame(PageTre))
  228.         button5.pack()
  229.         button6 = tk.Button(self, text="sumawydatkow",
  230.                             command=lambda: controller.show_frame(PageTre))
  231.         button6.pack()
  232.         button7 = tk.Button(self, text="szkola",
  233.                             command=lambda: controller.show_frame(PageTre))
  234.         button7.pack()
  235.         button8 = tk.Button(self, text="telefon",
  236.                             command=lambda: controller.show_frame(PageTre))
  237.         button8.pack()
  238.  
  239. class PageOne(tk.Frame):
  240.  
  241.     def __init__(self, parent, controller):
  242.         tk.Frame.__init__(self, parent)
  243.         label = tk.Label(self, text="Page One!!!", font=LARGE_FONT)
  244.         label.pack(pady=10,padx=10)
  245.  
  246.         button = tk.Button(self, text="glowna",
  247.                             command=lambda: controller.show_frame(StartPage))
  248.         button.pack()
  249.  
  250.        
  251.  
  252.  
  253. class PageTwo(tk.Frame):
  254.  
  255.     def __init__(self, parent, controller):
  256.         tk.Frame.__init__(self, parent)
  257.         label = tk.Label(self, text="Page One!!!", font=LARGE_FONT)
  258.         label.pack(pady=10,padx=10)
  259.  
  260.         button = tk.Button(self, text="glowna",
  261.                             command=lambda: controller.show_frame(StartPage))
  262.         button.pack()
  263.        
  264.        
  265.    
  266.        
  267.        
  268.        
  269. class PageTre(tk.Frame):
  270.  
  271.     def __init__(self, parent, controller):
  272.         tk.Frame.__init__(self, parent)
  273.         label = tk.Label(self, text="Page One!!!", font=LARGE_FONT)
  274.         label.pack(pady=10,padx=10)
  275.  
  276.         button = tk.Button(self, text="glowna",
  277.                             command=lambda: controller.show_frame(StartPage))
  278.         button.pack()
  279. class PageFour(tk.Frame):
  280.  
  281.     def __init__(self, parent, controller):
  282.         tk.Frame.__init__(self, parent)
  283.         label = tk.Label(self, text="Page One!!!", font=LARGE_FONT)
  284.         label.pack(pady=10,padx=10)
  285.  
  286.         button = tk.Button(self, text="glowna",
  287.                             command=lambda: controller.show_frame(StartPage))
  288.         button.pack()
  289. class PageFive(tk.Frame):
  290.  
  291.     def __init__(self, parent, controller):
  292.         tk.Frame.__init__(self, parent)
  293.         label = tk.Label(self, text="Page One!!!", font=LARGE_FONT)
  294.         label.pack(pady=10,padx=10)
  295.  
  296.         button = tk.Button(self, text="glowna",
  297.                             command=lambda: controller.show_frame(StartPage))
  298.         button.pack()
  299. class PageSix(tk.Frame):
  300.  
  301.     def __init__(self, parent, controller):
  302.         tk.Frame.__init__(self, parent)
  303.         label = tk.Label(self, text="Page One!!!", font=LARGE_FONT)
  304.         label.pack(pady=10,padx=10)
  305.  
  306.         button = tk.Button(self, text="glowna",
  307.                             command=lambda: controller.show_frame(StartPage))
  308.         button.pack()
  309. class PageSeven(tk.Frame):
  310.  
  311.     def __init__(self, parent, controller):
  312.         tk.Frame.__init__(self, parent)
  313.         label = tk.Label(self, text="Page One!!!", font=LARGE_FONT)
  314.         label.pack(pady=10,padx=10)
  315.  
  316.         button = tk.Button(self, text="glowna",
  317.                             command=lambda: controller.show_frame(StartPage))
  318.         button.pack()
  319. class PageEight(tk.Frame):
  320.  
  321.     def __init__(self, parent, controller):
  322.         tk.Frame.__init__(self, parent)
  323.         label = tk.Label(self, text="Page One!!!", font=LARGE_FONT)
  324.         label.pack(pady=10,padx=10)
  325.  
  326.         button = tk.Button(self, text="glowna",
  327.                             command=lambda: controller.show_frame(StartPage))
  328.         button.pack()
  329.      
  330.    
  331.  
  332.    
  333. app = SeaofBTCapp()
  334. app.mainloop()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top