SHARE
TWEET

paintman

dachte Sep 20th, 2019 108 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python
  2.  
  3. import tkinter as tk
  4. import tkinter.messagebox as messagebox
  5.  
  6. #############
  7. # paintman - sanitised code sample demonstrating bug.
  8.  
  9. class MainWindow(tk.Frame):
  10.     def __init__(self, master=None):
  11.         super().__init__(master)
  12.         master.title("Paintmgr") # References the Toplevel for the MainWindow
  13.         self.master = master
  14.         self.grid()
  15.         self.create_widgets()
  16.  
  17.     def create_widgets(self):
  18.         thiscol = 0
  19.         tk.Label(self, text='Corner x').grid(row=0,column=thiscol)
  20.         tk.Label(self, text='Corner y').grid(row=1,column=thiscol)
  21.         tk.Label(self, text='Corner z').grid(row=2,column=thiscol)
  22.  
  23.         thiscol += 1
  24.         self.xcoord = tk.Entry(self)
  25.         self.xcoord.grid(row=0, column=thiscol)
  26.  
  27.         self.ycoord = tk.Entry(self)
  28.         self.ycoord.grid(row=1, column=thiscol)
  29.  
  30.         self.zcoord = tk.Entry(self)
  31.         self.zcoord.grid(row=2, column=thiscol)
  32.  
  33.         thiscol += 1
  34.         tk.Button(self, text='Work on', command=self.WorkOnButtonAction).grid(row=0, column=thiscol)
  35.         tk.Button(self, text='Quit',    command=self.QuitButtonAction).grid(  row=1, column=thiscol)
  36.  
  37.         for coliter in range(0,thiscol):
  38.             self.columnconfigure(coliter, weight=1, pad=20)
  39.         self.master.minsize(500,200)
  40.  
  41.     def QuitButtonAction(self):
  42.         self.master.destroy()
  43.     def WorkOnButtonAction(self):
  44.         # Validate the original window's data before making a new window.
  45.         # If the user gave invalid data, give a popup and stop.
  46.  
  47.         if not (    (self.xcoord.get().isdigit) and
  48.                 (self.ycoord.get().isdigit) and
  49.                 (self.zcoord.get().isdigit)):
  50.             messagebox.showerror('Bad input', 'Input failed validation')
  51.             return
  52.  
  53.         WorkOnWindow = tk.Toplevel()
  54.         WorkOnWindow.title("Paimtmgr - Work")
  55.         WorkOnWindow.grid()
  56.  
  57.         thiscol = 0
  58.         tk.Label(WorkOnWindow, text=f'X:').grid(row=0, column=thiscol)
  59.         tk.Label(WorkOnWindow, text=f'Y:').grid(row=1, column=thiscol)
  60.         tk.Label(WorkOnWindow, text=f'Z:').grid(row=2, column=thiscol)
  61.         tk.Label(WorkOnWindow, text=f'Status:').grid(row=3, column=thiscol)
  62.         thiscol += 1
  63.  
  64.         tk.Button(WorkOnWindow, text='Fetch',   command=self.FetchButtonAction).grid(row=0, column=thiscol)
  65.         tk.Button(WorkOnWindow, text='Edit',    command=self.EditButtonAction ).grid(row=1, column=thiscol)
  66.         tk.Button(WorkOnWindow, text='Push',    command=self.PushButtonAction ).grid(row=2, column=thiscol)
  67.  
  68.         thiscol += 1
  69.         tk.Label(WorkOnWindow, text='Close this window when done with it.\nPlease do not edit settings in the main window while using this one.\nPlease do not open multiples of this window.').grid(row=4, column=0, columnspan=5)
  70.  
  71.         for coliter in range(0,thiscol):
  72.             WorkOnWindow.columnconfigure(coliter, weight=1, pad=20)
  73.         WorkOnWindow.minsize(500,200)
  74.  
  75.     def FetchButtonAction(self):
  76.         pass
  77.     def EditButtonAction(self):
  78.         pass
  79.     def PushButtonAction(self):
  80.         pass
  81.  
  82. root = tk.Tk()
  83. app = MainWindow(master=root)
  84. 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
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top