Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/env python
- # GUI v1.0
- # 25.12.2011 cmiN
- #
- # This is just a simple app for my future project.
- from Tkinter import *
- import urllib
- class GUI(Frame):
- """
- Main GUI class inherited from Frame.
- Like this, we create our main frame with all widgets on it.
- """
- def __init__(self, master=None, width=300, height=300):
- Frame.__init__(self, master, width=width, height=height)
- self.grid()
- self.create_widgets()
- self.set_behavior()
- def create_widgets(self):
- """ Here are born our lovely widgets. """
- self.first = IntVar()
- self.second = IntVar()
- self.select = IntVar()
- self.menuButton = Menubutton(self, text="New")
- self.menuButton.menu = Menu(self.menuButton, tearoff=0)
- self.label = Label(self, text="Welcome!", fg="orange")
- self.label2 = Label(self, text="Link:")
- self.scrollbar = Scrollbar(self, orient="horizontal", command=self.__scroll_handler)
- self.entry = Entry(self, width=20, fg="grey", xscrollcommand=self.scrollbar.set)
- self.button = Button(self, text="Quit", command=self.quit, width=5)
- self.button2 = Button(self, text="Get", command=self.get_url, width=5)
- self.menuButton.grid()
- self.label.grid(row=1, column=0, pady=10, columnspan=3)
- self.label2.grid(row=2, column=0)
- self.entry.grid(row=2, column=1, columnspan=2, padx=10)
- self.scrollbar.grid(row=3, column=1, columnspan=2, padx=10, sticky=W+E)
- self.button2.grid(row=4, column=1, sticky="se", pady=5, columnspan=1)
- self.button.grid(row=4, column=2, pady=5, sticky="sw", columnspan=1)
- self.label2.grid_forget()
- def set_behavior(self):
- self.menuButton["menu"] = self.menuButton.menu
- self.menuButton.menu.add("checkbutton", label="First", variable=self.first, command=self.show)
- self.menuButton.menu.add("checkbutton", label="Second", variable=self.second)
- self.menuButton.menu.add("radiobutton", label="a", variable=self.select, value=0)
- self.menuButton.menu.add("radiobutton", label="b", variable=self.select, value=1)
- self.menuButton.menu.add("radiobutton", label="c", variable=self.select, value=2)
- self.entry.insert(0, "Enter link...")
- self.entry.bind("<Button-1>", self.__event_handler)
- self.second.set(1)
- def show(self):
- print self.select.get()
- def get_url(self):
- fout = open("index.html", "wt")
- sock = urllib.urlopen(self.entry.get())
- fout.write(sock.read())
- fout.close()
- def __scroll_handler(self, *args):
- if args[0] == "scroll":
- self.entry.xview_scroll(args[1], args[2])
- elif args[0] == "moveto":
- self.entry.xview_moveto(args[1])
- def __event_handler(self, event):
- if self.entry["fg"] == "grey":
- self.entry.delete(0, END)
- self.entry["fg"] = "black"
- def main():
- app = GUI()
- app.master.title("GUI v1.0")
- #app.grid_propagate(False)
- app.mainloop()
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement