小甲鱼 发表于 2015-5-25 16:50:36

已有 12 人购买  本主题需向作者支付 10 鱼币 才能浏览 购买主题

萌萌哒 发表于 2015-5-25 18:42:36

Python还在更新吗?

delphi369 发表于 2015-5-25 21:27:31

小甲鱼的PYTHON既全面又权威!太感谢了!

小甲鱼 发表于 2015-5-25 22:07:58

萌萌哒 发表于 2015-5-25 18:42
Python还在更新吗?

更新的~

小甲鱼 发表于 2015-5-25 22:08:06

delphi369 发表于 2015-5-25 21:27
小甲鱼的PYTHON既全面又权威!太感谢了!

谢谢哥们长期支持~

我是桃川人 发表于 2015-5-26 10:05:39

本帖最后由 我是桃川人 于 2015-5-26 10:07 编辑

这个说明早出就更好了~看官方英文理解不够。
赞~
请教一个问题,如何在tkinter里处理while?bind吗?怎么bind一个TCP监听呢?如:client = sock(AF_INET, SOCK_STREAM)
client.connect((HOST, PORT))
while True:
    data = clent.recv(1024)
    ...


小甲鱼 发表于 2015-5-26 18:22:48

Python3 将以下代码的 Tkinter 替换成 tkinter 即可:

"""
This recipe describes how to handle asynchronous I/O in an environment where
you are running Tkinter as the graphical user interface. Tkinter is safe
to use as long as all the graphics commands are handled in a single thread.
Since it is more efficient to make I/O channels to block and wait for something
to happen rather than poll at regular intervals, we want I/O to be handled
in separate threads. These can communicate in a threasafe way with the main,
GUI-oriented process through one or several queues. In this solution the GUI
still has to make a poll at a reasonable interval, to check if there is
something in the queue that needs processing. Other solutions are possible,
but they add a lot of complexity to the application.

Created by Jacob Hallén, AB Strakt, Sweden. 2001-10-17
"""
import Tkinter
import time
import threading
import random
import Queue

class GuiPart:
    def __init__(self, master, queue, endCommand):
      self.queue = queue
      # Set up the GUI
      console = Tkinter.Button(master, text='Done', command=endCommand)
      console.pack()
      # Add more GUI stuff here

    def processIncoming(self):
      """
      Handle all the messages currently in the queue (if any).
      """
      while self.queue.qsize():
            try:
                msg = self.queue.get(0)
                # Check contents of message and do what it says
                # As a test, we simply print it
                print msg
            except Queue.Empty:
                pass

class ThreadedClient:
    """
    Launch the main part of the GUI and the worker thread. periodicCall and
    endApplication could reside in the GUI part, but putting them here
    means that you have all the thread controls in a single place.
    """
    def __init__(self, master):
      """
      Start the GUI and the asynchronous threads. We are in the main
      (original) thread of the application, which will later be used by
      the GUI. We spawn a new thread for the worker.
      """
      self.master = master

      # Create the queue
      self.queue = Queue.Queue()

      # Set up the GUI part
      self.gui = GuiPart(master, self.queue, self.endApplication)

      # Set up the thread to do asynchronous I/O
      # More can be made if necessary
      self.running = 1
            self.thread1 = threading.Thread(target=self.workerThread1)
      self.thread1.start()

      # Start the periodic call in the GUI to check if the queue contains
      # anything
      self.periodicCall()

    def periodicCall(self):
      """
      Check every 100 ms if there is something new in the queue.
      """
      self.gui.processIncoming()
      if not self.running:
            # This is the brutal stop of the system. You may want to do
            # some cleanup before actually shutting it down.
            import sys
            sys.exit(1)
      self.master.after(100, self.periodicCall)

    def workerThread1(self):
      """
      This is where we handle the asynchronous I/O. For example, it may be
      a 'select()'.
      One important thing to remember is that the thread has to yield
      control.
      """
      while self.running:
            # To simulate asynchronous I/O, we create a random number at
            # random intervals. Replace the following 2 lines with the real
            # thing.
            time.sleep(rand.random() * 0.3)
            msg = rand.random()
            self.queue.put(msg)

    def endApplication(self):
      self.running = 0

rand = random.Random()
root = Tkinter.Tk()

client = ThreadedClient(root)
root.mainloop()

995956078 发表于 2015-9-18 10:54:09

小甲鱼 发表于 2015-5-25 22:08
谢谢哥们长期支持~

不用谢

泳爸 发表于 2016-9-5 19:09:01

anchor和side。。。expand和fill。。。

yejinhe1986 发表于 2016-11-24 22:08:17

谢谢分享啊

鲜红的落叶 发表于 2018-5-23 19:53:11

请问应该怎样做到左侧页面导航图?

学学看看 发表于 2018-10-19 18:54:28

nichengang 发表于 2019-8-15 08:09:06


谢谢分享啊

王小也 发表于 2022-8-31 21:47:32

思考了半天,自己的理解加上实践代码的结果展示,终于明白了anchor与side的区别

liuhongrun2022 发表于 2023-7-29 10:59:37

是不是fill=X不需要expand=True就可以默认填充,而其他比如fill=BOTH,fill=Y就需要expand=Ture来填充剩余位置?
页: [1]
查看完整版本: Tkinter 布局管理器:pack