예제 #1
0
    def bottom_button_row(self):
        ''' just to order a little bit'''
        _br_ = Frame(self)
        b1 = Button(_br_, text='Save', command=(lambda: self.save_it()))
        b1.pack(side="right", padx=10, pady=20)
        b1.focus()

        b2 = Button(_br_, text='Quit', command=(lambda: self.exit_pop()))
        b2.pack(side="right", padx=10, pady=4)
        _br_.pack(side="bottom", expand=True)
예제 #2
0
class HelpWindow(object):
    def __init__(self,master, title):
        self.top=Toplevel(master)
        self.value = ''
        self.top.geometry("300x300+300+300")
        self.l=Label(self.top,text=title)
        self.l.pack()
        self.b=Button(self.top,text='Ok',command=self.cleanup)
        self.b.pack()
        self.b.focus()
    def cleanup(self):
        self.top.destroy()
예제 #3
0
class closing_comment():
    def __init__(self, master):
        self._master = master
        self.interior = Frame(master, class_="closing")

        instruction_label_frame = Frame(self.interior, class_="closing")
        instruction_label_frame.pack(fill=X)

        self.title_font = tkfont.Font(family='Helvetica',
                                      size=18,
                                      weight="bold",
                                      slant="italic")
        self.content_font = tkfont.Font(family='Helvetica', size=14)
        self._label_instruction = Label(
            instruction_label_frame,
            text="Please give your overall comment to the system.",
            font=self.title_font)
        self._label_instruction.pack()

        # entry form
        self.var_entry = StringVar()
        entry_frame = Frame(self.interior, class_="entry")
        entry_frame.pack(fill=X)

        self._entry_comment = Entry(entry_frame,
                                    width=70,
                                    textvariable=self.var_entry)
        self._entry_comment.pack(side=LEFT, fill='both', expand=True)

        #button
        button_frame = Frame(self.interior, class_="Submit")
        button_frame.pack(fill=X)

        self._button_next = Button(button_frame,
                                   text="Submit",
                                   command=self.close_window,
                                   width=50,
                                   font=self.content_font)
        self._button_next.pack()
        self._button_next.bind("<Button-1>", self._on_button_submit)
        self._button_next.focus()

    def close_window(self):
        self._master.destroy()

    def _on_button_submit(self, event):
        # get the input from user
        print("var_entry:", self.var_entry.get())

        _log = open("log.txt", "a")
        _log.write("\nClosing comment: %s" % self.var_entry.get())
예제 #4
0
class conDialog(Toplevel):
        def __init__(self, parent, title):
                self.top = Toplevel(parent)
                self.top.wm_title(title)
                self.top.wm_minsize(width=200, height=250)

                self.parent = parent

                self.logger = Text(self.top, width=50, height=15)
                self.logger.pack(fill=BOTH, expand=1)
                self.logger.config(wrap=WORD)

                self.close = Button(self.top, text="Close",
                                    command=self.close)
                self.close.pack(fill=X, expand=0)
                self.close.focus()

                self.logger.tag_config('backlog', foreground="grey")
                self.logger.tag_config('ERR', foreground="IndianRed1")
            
                for e in range(len(ERR)):
                        if len(ERR[e][1]) > 1:
                                self.logger.insert(INSERT,
                                                   str(ERR[e][0] + "\n"),
                                                   ERR[e][1])
                        else:
                                self.logger.insert(INSERT,
                                                   str(ERR[e] + '\n'),
                                                   'backlog')
                self.logger.config(state=DISABLED)

        # destroys this Toplevel widget and sets the CON variable to None
        def close(self):
                self.top.destroy()
                global CON
                CON = None

        # method that places the text inside the log thats in the console
        #  also stores the messages in the backlog (ERR)
        def placeText(self, message):
                self.logger.config(state=NORMAL)
                ERR.append(message)
                
                if len(message[1]) > 1:
                        self.logger.insert(INSERT,
                                           str(message[0] + "\n"),
                                           message[1])
                else:
                        self.logger.insert(INSERT, message + "\n")
                
                self.logger.config(state=DISABLED)
예제 #5
0
    def __init__(self):
        Game.__init__(self)
        import socket
        self.local = self.host = socket.gethostbyname(
            socket.gethostname())  # Get local machine ip
        from Tkinter import Tk, PanedWindow, StringVar, Entry, Button, VERTICAL, HORIZONTAL, Label
        fenetre = Tk()
        fenetre.title('Socket parameters')
        self.netgame_win = PanedWindow(fenetre, orient=VERTICAL)
        host_zone = PanedWindow(self.netgame_win, orient=HORIZONTAL)
        host = StringVar()
        host.set(self.local)

        def modifHost(*args):
            self.host = host.get()
            if self.local == self.host:
                start_button.config(text="Create")
            else:
                start_button.config(text="Join")

        host.trace("w", modifHost)
        host_wid = Entry(host_zone, width=30, textvariable=host)
        host_wid.pack()
        host_label = Label(fenetre, text="Host (you are " + self.local + ") :")
        host_zone.add(host_label)
        host_zone.add(host_wid)
        self.netgame_win.add(host_zone)
        port_zone = PanedWindow(self.netgame_win, orient=HORIZONTAL)
        port = StringVar()
        self.port = 52333
        port.set(str(self.port))

        # adress_wid=Label(None, textvariable=self.cost, background='red',width=5, anchor=W)
        def modifPort(*args):
            self.port = port.get()

        port.trace("w", modifPort)
        port_wid = Entry(port_zone, width=30, textvariable=port)
        port_wid.pack()
        port_label = Label(fenetre, text="Port :")
        port_zone.add(port_label)
        port_zone.add(port_wid)
        self.netgame_win.add(port_zone)

        #Create the open button
        def start():
            fenetre.destroy()

        start_button = Button(self.netgame_win, text="Create", command=start)
        self.netgame_win.add(start_button)
        self.netgame_win.pack()
        fenetre.focus_set()
        start_button.focus()
        fenetre.mainloop()
        # Import socket module
        self.soc = socket.socket()  # Reserve a port for your service.
        if self.local == self.host:
            self.soc.bind((self.host, self.port))  # Bind to the port
            print "socket listening"
            self.soc.listen(5)  # Now wait for client connection.

            self.soc, addr = self.soc.accept(
            )  # Establish connection with client.
            print 'Got connection from', addr
            #self.soc.send('Thank you for connecting')
            #c.close()                # Close the connection
            self.firstplayer = choice([1, 2])
            print "FIRST PLAYER IS", 1
            self.soc.send(str(3 - self.firstplayer))
        else:
            self.soc.connect((self.host, self.port))
            print "connect ok"
            p = self.soc.recv(1024)
            try:
                self.firstplayer = int(p)
            except:
                print "error concerning first player, got ", p