Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # wutyewcie_tk_v2.py
- '''
- I suspect this project is far from complete whereas I also plan to make WUTYEWCIE Tk also create JavaScript code
- much as possible by menu selecting lines of python which should eventually prevent syntax errors so we can get a whole lot more work properly done. Always willing to accept help in any way to make WUTYEWCIE Tk hopefully super useful.
- '''
- from tkinter import *
- ww = 1280
- hh = 620
- root = Tk()
- root.title('WUTYEWCIE Tk') # Pronounced as What-You-See-Toolkit
- root.state('zoomed')
- canvas = Canvas(width=ww, height=hh)
- canvas.pack()
- widgets = []
- def about():
- messagebox.showinfo("About", "WUTYEWCIE Tk\nVersion: 1.0.0\nAuthors: Facebook Tkinter Groups\nDate: 2020-08-03")
- def import_file():
- import_file = filedialog.askopenfilename(initialdir = "/",title = "Select file",filetypes = (("jpeg files","*.jpg"),("all files","*.*")))
- print(import_file)
- def import_url(): ### ZZZ
- import_url = simpledialog.askstring("Input", "Enter URL:", parent=root)
- print(import_url)
- def export_html():
- export_html = filedialog.asksaveasfilename(initialdir = "/",title = "Select file",filetypes = (("jpeg files","*.jpg"),("all files","*.*")))
- print(export_html)
- def export_py():
- ## save custom layout as a Python script
- # loop through all added widgets to write the code
- code = []
- for widget in widgets:
- code += ['# ' + widget.winfo_class()]
- code += [widget.winfo_name() + ' = ' + widget_type + '(' + root.winfo_class() + ')']
- for key, value in widget.config().items():
- code += [widget.winfo_name() + '.' + key + ' = ' + repr(value)]
- code += ['']
- code = '\n'.join(code)
- savefile = filedialog.asksaveasfilename(initialdir = "/",title = "Select file",filetypes = (("python files","*.py"),("all files","*.*")))
- if savefile:
- with open(savefile, 'w') as file:
- file.write(code)
- messagebox.showinfo('Success', 'File saved successfully')
- else:
- messagebox.showerror('Error', 'File not saved')
- def widget_options(widget):
- code = []
- code += ['# ' + widget.winfo_class()]
- code += [widget.winfo_name() + ' = ' + widget_type + '(' + root.winfo_class() + ')']
- for key, value in widget.config().items():
- code += [widget.winfo_name() + '.' + key + ' = ' + repr(value)]
- code = '\n'.join(code)
- return code
- def import_code():
- openfile = filedialog.askopenfilename(initialdir = "/",title = "Select file",filetypes = (("python files","*.py"),("all files","*.*")))
- if openfile:
- with open(openfile, 'r') as file:
- code = file.read()
- exec(code)
- else:
- messagebox.showerror('Error', 'File not found')
- options = []
- def widget_options(widget):
- global options
- i = 10
- def iii(i=i):
- i += 15
- return i
- options = []
- '''
- # this section will have to be done very differently
- yscrollbar = Scrollbar(root)
- yscrollbar.pack(side=RIGHT, fill=Y)
- options_list = Listbox(root, yscrollcommand = yscrollbar.set, font=("Verdana", 8), bg="white", fg="blue")
- options_list.place(x=160, y=i, width=160, height=hh-20)
- yscrollbar.config(command = options_list.yview)
- for option in widget.keys():
- if '.' not in option:
- #entry_form = Entry(option_label, font=("Verdana", 8), bg="white", fg="blue")
- #entry_form.place(x=i, y=iii(), width=145, height=15)
- options.append(option)
- # print(options)
- # options_list.insert(END, option) <-- forget this method
- '''
- def more_options(event):
- 0 # displays all othe widget options, but... in a TopWindow instead
- # import and export dropdow-menu
- menu = Menu(root)
- root.config(menu=menu)
- subMenu = Menu(menu)
- menu.add_cascade(label='Import', menu=subMenu)
- subMenu.add_command(label='Import Python Script', command=import_file)
- subMenu.add_command(label='Import URL*', command=import_url)
- subMenu.add_separator()
- subMenu.add_command(label='Export Python Script', command=export_py)
- subMenu.add_command(label='Export HTML5*/JS', command=export_html)
- subMenu = Menu(menu)
- menu.add_cascade(label='Help', menu=subMenu)
- subMenu.add_command(label='About', command=about)
- subMenu.add_command(label='Exit', command=root.quit)
- ## create equal length draggable widgets
- # box label
- box_label = Label(canvas, text='Label', bg='green', fg='white', font=('Arial', 12))
- box_label.place(x=10, y=10, width=140, height=27)
- # button label
- button_label = Label(canvas, text='Button', bg='green', fg='white', font=('Arial', 12))
- button_label.place(x=10, y=40, width=140, height=27)
- # checkbox label
- checkbox_label = Label(canvas, text='CheckButton', bg='green', fg='white', font=('Arial', 12))
- checkbox_label.place(x=10, y=70, width=140, height=27)
- # radiobutton label
- radiobutton_label = Label(canvas, text='RadioButton', bg='green', fg='white', font=('Arial', 12))
- radiobutton_label.place(x=10, y=100, width=140, height=27)
- # entry label
- entry_label = Label(canvas, text='Entry', bg='green', fg='white', font=('Arial', 12))
- entry_label.place(x=10, y=130, width=140, height=27)
- # option_label label
- listbox_label = Label(canvas, text='ListBox', bg='green', fg='white', font=('Arial', 12))
- listbox_label.place(x=10, y=160, width=140, height=27)
- # message label
- message_label = Label(canvas, text='Message', bg='green', fg='white', font=('Arial', 12))
- message_label.place(x=10, y=190, width=140, height=27)
- # to see more options
- more_options_label = Label(canvas, text='Primary Widget Options', bg=None, fg='black', font=('Arial', 9))
- more_options_label.place(x=6, y=225, width=140, height=20)
- # to see more options
- more_options_label = Label(canvas, text='TO SEE MORE OPTIONS', bg='orange', fg='white', font=('Arial', 8)) # <-- will be grayed out when widgets are unselected
- more_options_label.place(x=10, y=hh-24, width=140, height=20)
- def wxy():
- x,y = root.winfo_x()+5, root.winfo_y()+60
- return x,y
- def xy():
- x,y = root.winfo_pointerxy()
- return x,y
- def on_start(event):
- global __widget
- __widget = 0
- def on_start_2(event):
- global __widget
- __widget = event.widget
- def on_drag(event):
- global __widget
- x,y = xy()
- wx,wy = wxy()
- if x-wx-15 > x1:
- if not __widget:
- widget = event.widget
- ## enable dragging a copy selected of widget onto label GUI_area to place it
- # get x1,y1,x2,y2 of GUI_area
- widget_type = widget.cget("text").title()
- new_widget = eval(widget_type + '()')
- if widget_type in ["Button", "Label"]:
- new_widget.place(x=x-wx-10, y=y-wy, width=widget.winfo_width()+10, height=widget.winfo_height()+10)
- else:
- new_widget.place(x=x-wx-10, y=y-wy)
- __widget = new_widget
- new_widget.bind("<ButtonPress-1>", on_start_2)
- new_widget.bind("<B1-Motion>", on_drag_2)
- new_widget.bind("<ButtonRelease-1>", on_drop)
- widgets.append(new_widget)
- widget_options(new_widget)
- if __widget:
- __widget.place(x=x-wx-10, y=y-wy)
- def on_drag_2(event):
- x,y = xy()
- wx,wy = wxy()
- widget = event.widget
- widget.place(x=x-wx-10, y=y-wy)
- def on_drop(event):
- x,y = xy()
- wx,wy = wxy()
- if __widget:
- if x-wx-15 < x1:
- print(widgets)
- print(__widget)
- __widget.destroy()
- widgets.remove(__widget)
- print("deleted widget")
- else:
- __widget.place(x=x-wx-10, y=y-wy)
- print("placed widget")
- x1 = 150
- y1 = 5
- x2 = ww-x1-10
- y2 = hh-5
- GUI_area = Label(canvas, bg='#8470FF', fg='black', relief='sunken')
- GUI_area.place(x=x1, y=y1, width=x2, height=y2)
- # define drag-and-drop of place() labels
- box_label.bind("<ButtonPress-1>", on_start)
- box_label.bind("<B1-Motion>", on_drag)
- box_label.bind("<ButtonRelease-1>", on_drop)
- button_label.bind("<ButtonPress-1>", on_start)
- button_label.bind("<B1-Motion>", on_drag)
- button_label.bind("<ButtonRelease-1>", on_drop)
- checkbox_label.bind("<ButtonPress-1>", on_start)
- checkbox_label.bind("<B1-Motion>", on_drag)
- checkbox_label.bind("<ButtonRelease-1>", on_drop)
- radiobutton_label.bind("<ButtonPress-1>", on_start)
- radiobutton_label.bind("<B1-Motion>", on_drag)
- radiobutton_label.bind("<ButtonRelease-1>", on_drop)
- entry_label.bind("<ButtonPress-1>", on_start)
- entry_label.bind("<B1-Motion>", on_drag)
- entry_label.bind("<ButtonRelease-1>", on_drop)
- listbox_label.bind("<ButtonPress-1>", on_start)
- listbox_label.bind("<B1-Motion>", on_drag)
- listbox_label.bind("<ButtonRelease-1>", on_drop)
- message_label.bind("<ButtonPress-1>", on_start)
- message_label.bind("<B1-Motion>", on_drag)
- message_label.bind("<ButtonRelease-1>", on_drop)
- more_options_label.bind("<ButtonPress-1>", more_options)
- #
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement